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