(define (return x) x)
(define (bounce thunk) (call thunk))
(define (call thunk) (thunk))
(define (fact-iter n acc)
(if (zero? n)
(return acc)
(bounce
(lambda ()
(fact-iter
(- n 1)
(* acc n))))))
(define (mem? n lst)
(cond ((null? lst) (return #f))
((= (car lst ) n) (return #t))
(else (bounce
(lambda ()
(mem? n (cdr lst)))))))
(define (fib n)
(fib-iter n 0 0 1))
(define (fib-iter n i small large)
(if (< i n)
(bounce
(lambda ()
(fib-iter n (+ i 1) large (+ large small))))
(return small)))
; > (fact-iter 5 1)
; 120
; > (mem? 5 (list 1 2 3 4 5 6))
; #t
; > (fib 8)
; 21 | | The identity function.
Function application. The thunk is called.
|