1 This function is developed in *The Seasoned Schemer* pp. 165-177. It accepts a list `lst` and returns `#t` or `#f` depending on whether any atom appears in `lst` twice in a row. The list is interpreted as though it were flattened: all embedded lists are collapsed into the topmost level, and empty list elements are ignored. However, no flattened copy of the list is ever constructed.
6 (and (not (pair? x)) (not (null? x))))
9 (letrec ([yield (lambda (x) x)]
10 [resume (lambda (x) x)]
13 ; this is the only case where walk terminates naturally
15 [(atom? (car l)) (begin
17 (set! resume k2) ; now calling resume with val will ignore val
18 ; and continue with the final line of (begin ... (walk (cdr l)))
19 ; when the next line is executed, yield will be bound to k1 or k3
21 ; the previous yield line will never return, but the following line will be executed when resume is called
24 ; walk will only ever return when a '() is reached, and will in that case return a '()
27 [next (lambda () ; next is a thunk
29 (set! yield k3) ; now calling yield with val will return val from the call to next
30 ; when the next line is executed, resume will be bound to k2
37 ; n will fail to be an atom iff we've walked to the end of the list, and (resume 'blah) returned naturally
41 (set! yield k1) ; now calling yield with val will bind fst to val and continue with the (cond ...) block below
43 ; the next line will be executed only when lst contains no atoms
46 [(atom? fst) (check fst)]
50 (delta '(((a b) ()) (c (d ())))) ; ~~> #f
51 (delta '(((a b) ()) (b (d ())))) ; ~~> #t
52 (delta '(((a b) ()) (c (d (d))))) ; ~~> #t
53 (delta '(((a b c) ()) (c (d ())))) ; ~~> #t
54 (delta '(((a b) ()) (c (d ()) c))) ; ~~> #f