Update generator syntax
This commit is contained in:
parent
7682d622a8
commit
921d770986
11
d-.scm
11
d-.scm
@ -9,7 +9,7 @@
|
||||
for
|
||||
partial
|
||||
argmin
|
||||
make-generator))
|
||||
generator))
|
||||
|
||||
(define-syntax ~>
|
||||
(syntax-rules ()
|
||||
@ -67,3 +67,12 @@
|
||||
(lambda (k value)
|
||||
(set! thunk k)
|
||||
value))))
|
||||
|
||||
(define-syntax generator
|
||||
(lambda (x)
|
||||
(syntax-case x ()
|
||||
[(generator expr ...)
|
||||
(with-syntax ([yield (datum->syntax x 'yield)])
|
||||
#'(make-generator
|
||||
(lambda (yield)
|
||||
expr ...)))])))
|
||||
|
6
test.scm
6
test.scm
@ -85,13 +85,13 @@
|
||||
(test
|
||||
(assert-equal (argmin cdr < '(a . 5) '(b . 2) '(c . 3)) '(b . 2))))
|
||||
|
||||
(define-test make-generator
|
||||
(define-test generator
|
||||
(test
|
||||
(define number-generator
|
||||
(make-generator (lambda (yield)
|
||||
(generator
|
||||
(let loop ([i 1])
|
||||
(yield i)
|
||||
(loop (1+ i))))))
|
||||
(loop (1+ i)))))
|
||||
(assert-equal (number-generator) 1)
|
||||
(assert-equal (number-generator) 2)
|
||||
(assert-equal (number-generator) 3)
|
||||
|
Loading…
Reference in New Issue
Block a user