collatz-via-closures.scm 187 B

123456789101112131415
  1. ;; do a odd (+ (* 3 n) 1), even (/ 2 n)
  2. ;; and use closures to do it!
  3. (define (generator n)
  4. (lambda (m)
  5. (set! n (+ 1 n))
  6. (* m n)))
  7. (define thunk (generator 5))
  8. (thunk 10)