summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
61612ba)
Signed-off-by: Jim Pryor <profjim@jimpryor.net>
; is this the only case where walk returns a non-atom?
[(null? l) '()]
[(atom? (car l)) (begin
; is this the only case where walk returns a non-atom?
[(null? l) '()]
[(atom? (car l)) (begin
(set! resume k2) ; now what will happen when resume is called?
; when the next line is executed, what will yield be bound to?
(set! resume k2) ; now what will happen when resume is called?
; when the next line is executed, what will yield be bound to?
; when will the next line be executed?
(walk (cdr l)))]
[else (begin
; when will the next line be executed?
(walk (cdr l)))]
[else (begin
(walk (car l))
(walk (cdr l)))]))]
[next (lambda () ; next is a thunk
(walk (car l))
(walk (cdr l)))]))]
[next (lambda () ; next is a thunk
(set! yield k3) ; now what will happen when yield is called?
; when the next line is executed, what will resume be bound to?
(set! yield k3) ; now what will happen when yield is called?
; when the next line is executed, what will resume be bound to?
[check (lambda (prev)
(let ([n (next)])
(cond
[check (lambda (prev)
(let ([n (next)])
(cond
; when will n fail to be an atom?
[else #f])))])
(lambda (lst)
; when will n fail to be an atom?
[else #f])))])
(lambda (lst)
+ (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?
(set! yield k1) ; now what will happen when yield is called?
(walk lst)
; when will the next line be executed?
(cond
[(atom? fst) (check fst)]
; when will fst fail to be an atom?
(cond
[(atom? fst) (check fst)]
; when will fst fail to be an atom?
; this is the only case where walk terminates naturally
[(null? l) '()]
[(atom? (car l)) (begin
; this is the only case where walk terminates naturally
[(null? l) '()]
[(atom? (car l)) (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
(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
; the previous yield line will never return, but the following line will be executed when resume is called
(walk (cdr l)))]
[else (begin
; the previous yield line will never return, but the following line will be executed when resume is called
(walk (cdr l)))]
[else (begin
(walk (car l))
(walk (cdr l)))]))]
[next (lambda () ; next is a thunk
(walk (car l))
(walk (cdr l)))]))]
[next (lambda () ; next is a thunk
(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
(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
[check (lambda (prev)
(let ([n (next)])
(cond
[check (lambda (prev)
(let ([n (next)])
(cond
; 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)
; 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 (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
(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
(cond
[(atom? fst) (check fst)]
[else #f])
(cond
[(atom? fst) (check fst)]
[else #f])