-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcc.scm
24 lines (19 loc) · 843 Bytes
/
cc.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
(define (generate-one-element-at-a-time lst)
;; Hand the next item from a-list to "return" or an end-of-list marker
(define (control-state return)
(for-each
(lambda (element)
(call/cc ;;where after indexing one element and move to another element
(lambda (resume-here)
;; Grab the current continuation
(set! control-state resume-here)
(return element))))
lst)
(return 'you-fell-off-the-end))
;; This is the actual generator, producing one item from a-list at a time
(define (generator)
(call/cc control-state));;where generator return passing as arg to control-state
;; Return the generator
generator)
(define generate-digit
(generate-one-element-at-a-time '(0 1 2)))