10.04 adder-with-letcc

10.04 adder-with-letcc -...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
;; 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)))))
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; 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"))))...
View Full Document

This note was uploaded on 02/06/2008 for the course CS 1102 taught by Professor Fisler during the Fall '07 term at WPI.

Page1 / 2

10.04 adder-with-letcc -...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online