;; CS1102 -- creating (lambda (hole) ...) with let/cc ;; Kathi Fisler ;; october 3, 2007 ;; code examples from lecture ;; THIS MATERIAL IS NOT COVERED ON THE FINAL ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; the original adder program without scripts (define (request-num promptstr) (begin (printf "~a: " promptstr) (read))) (define (add1) (printf "Sum is ~a~n" (+ (request-num "first num") (request-num "second num")))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; the adder program using let/cc to create the lambda holes (define-script (request-num/k promptstr action) (begin (printf "~a: " promptstr) (action (read)))) (define (add1/k) (printf "Sum is ~a~n" (+ (let/cc k (request-num/k "first num" k)) (let/cc k (request-num/k "second num" k))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; doesn't work, since only computation waiting for a script ;; is termination (define-script (request-num promptstr) (let/cc k (begin (printf "~a: " promptstr) (k (read))))) (define (add2/k) (printf "Sum is ~a~n" (+ (request-num "first num") (request-num "second num")))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; a version of adder with scripts and let/cc that ;; preserves the code of the original function (define-script (make-web-request promptstr k) (begin (printf "~a: " promptstr) (k (read)))) (define (request-num promptstr) (let/cc k (make-web-request promptstr k))) (define (add3/k) (printf "Sum is ~a~n" (+ (request-num "first num") (request-num "second num"))))