fix PR 11123: 0-ary generator yield
This commit is contained in:
parent
65c245cdc7
commit
e077b87d50
|
@ -112,6 +112,9 @@
|
|||
(in-producer (generator () body0 body ... stop-value) stop-value)])
|
||||
(lambda (stx)
|
||||
(syntax-case stx ()
|
||||
[(() (_ body0 body ...))
|
||||
#'[()
|
||||
(in-producer (generator () body0 body ... stop-value) stop-value)]]
|
||||
[((id ...) (_ body0 body ...))
|
||||
(with-syntax ([(stops ...) (syntax-case #'((id stop-value) ...) ()
|
||||
[((x v) ...) #'(v ...)])])
|
||||
|
|
|
@ -1281,6 +1281,32 @@
|
|||
#t
|
||||
;; loop args
|
||||
())])]
|
||||
[[() (_ producer stop more ...)]
|
||||
(with-syntax ([(more* ...) (generate-temporaries #'(more ...))])
|
||||
#'[()
|
||||
(:do-in
|
||||
([(producer*) producer] [(more*) more] ...
|
||||
[(stop?) (let ([s stop])
|
||||
(if (procedure? s)
|
||||
s
|
||||
(lambda (args)
|
||||
(and (not (null? args))
|
||||
(eq? (car args) s)))))])
|
||||
;; outer check
|
||||
#t
|
||||
;; loop bindings
|
||||
()
|
||||
;; pos check
|
||||
#t
|
||||
;; inner bindings
|
||||
([(check) (call-with-values (lambda () (producer* more* ...))
|
||||
(lambda vs vs))])
|
||||
;; pre guard
|
||||
(not (stop? check))
|
||||
;; post guard
|
||||
#t
|
||||
;; loop args
|
||||
())])]
|
||||
;; multiple-values version
|
||||
[[(id ...) (_ producer stop more ...)]
|
||||
(with-syntax ([(more* ...) (generate-temporaries #'(more ...))])
|
||||
|
|
|
@ -242,6 +242,7 @@
|
|||
(for/list ([(x i) (in-indexed (in-generator (yield 1) (yield 2) (yield 3)))])
|
||||
(list x i)))
|
||||
|
||||
;; test multiple values for in-generator
|
||||
(test '[(1 2) (3 4)] 'for*-generator
|
||||
(for*/list ([(n after)
|
||||
(in-generator
|
||||
|
@ -249,6 +250,12 @@
|
|||
(yield 3 4))])
|
||||
(list n after)))
|
||||
|
||||
;; test 0-ary yields
|
||||
(test '(0 1 2) 'no-bind-in-generator
|
||||
(for/list ([() (in-generator (yield) (yield) (yield))]
|
||||
[i (in-naturals)])
|
||||
i))
|
||||
|
||||
(let ([helper (lambda (i)
|
||||
(yield (add1 i)))])
|
||||
(test '(1 2 3) 'parameterized-yield
|
||||
|
|
Loading…
Reference in New Issue
Block a user