Advertisement
Guest User

Untitled

a guest
Dec 5th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Racket 0.57 KB | None | 0 0
  1. (define (combine-2 pred? bin un zero exc)
  2.   (call/cc
  3.    (lambda (exit)
  4.      (letrec
  5.          ((f (lambda (xs)
  6.                (if (empty? xs)
  7.                    zero
  8.                    (if (pred? (first xs))
  9.                        (exit exc)
  10.                        (bin (first xs) (f (rest xs))))))))
  11.        f))))
  12.  
  13. (define product
  14.   (combine zero?
  15.            (trace *)
  16.            id
  17.            1
  18.            0))
  19.  
  20. (product '(1 2 3 4)
  21. ; 24
  22.  
  23. (product '(1 4 8 2 3 9 0 2 3 0))
  24. ; define-values: assignment disallowed;
  25. ; cannot re-define a constant
  26. ;  constant: product
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement