[plt-scheme] "Standard" coroutine library suitable for building filters as well as generators

From: Tony Garnock-Jones (tonyg at lshift.net)
Date: Mon Apr 5 16:00:49 EDT 2010

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

(define (print-all)
  (display "FIRST")
  (do ()
    (display (yield))

(let ((pa (generator () (print-all))))
  (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.

-------------- 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>

Posted on the users mailing list.