eval3.scm 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. ; Part of Scheme 48 1.9. See file COPYING for notices and license.
  2. ; Authors: Richard Kelsey
  3. (define-local-syntax (define-primitive id nargs)
  4. (let ((args (reverse (list-tail '(z y x) (- '3 nargs)))))
  5. `(define (,id . ,args)
  6. (call-primitively ,id . ,args))))
  7. (define-primitive ashl 2)
  8. (define-primitive ashr 2)
  9. (define-primitive = 2)
  10. (define-primitive bitwise-and 2)
  11. (define (input-type pred coercer) ;Alonzo wins
  12. (lambda (f) (f pred coercer)))
  13. (define (input-type-predicate type) (type (lambda (x y) y x)))
  14. (define (input-type-coercion type) (type (lambda (x y) x y)))
  15. (define (no-coercion x) x)
  16. (define (odd? x)
  17. (= 1 (bitwise-and x 1)))
  18. (define (extract-odd x)
  19. (ashr x 1))
  20. (define any-> (input-type (lambda (x) x #t) no-coercion))
  21. (define odd-> (input-type odd? extract-odd))
  22. (define (test x y)
  23. (if (and ((input-type-predicate any->) x)
  24. ((input-type-predicate odd->) y))
  25. (let ((a ((input-type-coercion any->) x))
  26. (b ((input-type-coercion odd->) y)))
  27. (+ a b))
  28. x))