diff --git a/d-.scm b/d-.scm index a01fb1a..387c2d8 100644 --- a/d-.scm +++ b/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 ...)))]))) diff --git a/test.scm b/test.scm index b916069..5b539bd 100644 --- a/test.scm +++ b/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) - (let loop ([i 1]) - (yield i) - (loop (1+ i)))))) + (generator + (let loop ([i 1]) + (yield i) + (loop (1+ i))))) (assert-equal (number-generator) 1) (assert-equal (number-generator) 2) (assert-equal (number-generator) 3)