-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerator.scm
More file actions
30 lines (27 loc) · 886 Bytes
/
Copy pathgenerator.scm
File metadata and controls
30 lines (27 loc) · 886 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
(define-module (generator)
#:export (generator yield))
(define (make-generator-passing-yield generator-defn-fn)
(define yield-tag (make-prompt-tag 'yield))
(define (yield . args)
(apply abort-to-prompt yield-tag args))
(define next (generator-defn-fn yield))
(define (call-with-yield-prompt f)
(call-with-prompt yield-tag
f
(lambda (continue . return-vals)
(set! next continue)
(apply values return-vals))))
(lambda args
(call-with-yield-prompt
(lambda () (apply next args)))))
(define-syntax-parameter yield
(lambda (stx)
(syntax-violation
'yield
"Yield is undefined outside of a generator expression"
stx)))
(define-syntax-rule (generator args body ...)
(make-generator-passing-yield
(lambda (yield%)
(syntax-parameterize ((yield (identifier-syntax yield%)))
(lambda args body ...)))))