From: Jim Pryor Date: Tue, 21 Dec 2010 12:04:35 +0000 (-0500) Subject: cps: add some begins X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=commitdiff_plain;h=413169d31f1670ffd98d2af8a962c050151cf662 cps: add some begins Signed-off-by: Jim Pryor --- diff --git a/cps_and_continuation_operators.mdwn b/cps_and_continuation_operators.mdwn index fadd34d3..f619fc0f 100644 --- a/cps_and_continuation_operators.mdwn +++ b/cps_and_continuation_operators.mdwn @@ -357,10 +357,10 @@ Here is the hardest example. Try to figure out what this function does: ; is this the only case where walk returns a non-atom? [(null? l) '()] [(atom? (car l)) (begin - (let/cc k2 + (let/cc k2 (begin (set! resume k2) ; now what will happen when resume is called? ; when the next line is executed, what will yield be bound to? - (yield (car l))) + (yield (car l)))) ; when will the next line be executed? (walk (cdr l)))] [else (begin @@ -368,10 +368,10 @@ Here is the hardest example. Try to figure out what this function does: (walk (car l)) (walk (cdr l)))]))] [next (lambda () ; next is a thunk - (let/cc k3 + (let/cc k3 (begin (set! yield k3) ; now what will happen when yield is called? ; when the next line is executed, what will resume be bound to? - (resume 'blah)))] + (resume 'blah))))] [check (lambda (prev) (let ([n (next)]) (cond @@ -380,11 +380,11 @@ Here is the hardest example. Try to figure out what this function does: ; when will n fail to be an atom? [else #f])))]) (lambda (lst) - (let ([fst (let/cc k1 + (let ([fst (let/cc k1 (begin (set! yield k1) ; now what will happen when yield is called? (walk lst) ; when will the next line be executed? - (yield '()))]) + (yield '())))]) (cond [(atom? fst) (check fst)] ; when will fst fail to be an atom? diff --git a/hints/cps_hint_4.mdwn b/hints/cps_hint_4.mdwn index 9804ed62..13add0a2 100644 --- a/hints/cps_hint_4.mdwn +++ b/hints/cps_hint_4.mdwn @@ -13,11 +13,11 @@ This function is developed in *The Seasoned Schemer* pp. 165-177. It accepts a l ; this is the only case where walk terminates naturally [(null? l) '()] [(atom? (car l)) (begin - (let/cc k2 + (let/cc k2 (begin (set! resume k2) ; now calling resume with val will ignore val ; and continue with the final line of (begin ... (walk (cdr l))) ; when the next line is executed, yield will be bound to k1 or k3 - (yield (car l))) + (yield (car l)))) ; the previous yield line will never return, but the following line will be executed when resume is called (walk (cdr l)))] [else (begin @@ -25,10 +25,10 @@ This function is developed in *The Seasoned Schemer* pp. 165-177. It accepts a l (walk (car l)) (walk (cdr l)))]))] [next (lambda () ; next is a thunk - (let/cc k3 + (let/cc k3 (begin (set! yield k3) ; now calling yield with val will return val from the call to next ; when the next line is executed, resume will be bound to k2 - (resume 'blah)))] + (resume 'blah))))] [check (lambda (prev) (let ([n (next)]) (cond @@ -37,11 +37,11 @@ This function is developed in *The Seasoned Schemer* pp. 165-177. It accepts a l ; n will fail to be an atom iff we've walked to the end of the list, and (resume 'blah) returned naturally [else #f])))]) (lambda (lst) - (let ([fst (let/cc k1 + (let ([fst (let/cc k1 (begin (set! yield k1) ; now calling yield with val will bind fst to val and continue with the (cond ...) block below (walk lst) ; the next line will be executed only when lst contains no atoms - (yield '()))]) + (yield '())))]) (cond [(atom? fst) (check fst)] [else #f])