[plt-scheme] "Standard" coroutine library suitable for building filters as well as generators
Scott McLoughlin wrote:
> (let ((pa (print-all))) ; "instantiates" the coroutine, here with no
> initialization arguments
> (resume pa 4) ; this pumps values to a pending "receive"
> within the coroutine
> (resume pa 2)
> (resume pa 6))
I would have expected (yield) to be just your (resume), but it turns out
not to be. Attached is a variant on generator/yield that permits
bidirectional communication with a generator. Your print-all example
becomes:
(define (print-all)
(display "FIRST")
(newline)
(do ()
(#f)
(display (yield))
(newline)))
(let ((pa (generator () (print-all))))
(pa)
(pa 1)
(pa 2)
(pa 3))
Be warned, I hacked it together just now, and while it's received light
testing and looks approximately like the right kind of thing to have
written, I wouldn't put it into production without some proper test cases.
Tony
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: bidi-generator.ss
URL: <http://lists.racket-lang.org/users/archive/attachments/20100406/3af55f2f/attachment.ksh>