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

From: Scott McLoughlin (scott at adrenaline.com)
Date: Mon Apr 5 15:03:23 EDT 2010

In addition to generators via yield, I'm also looking for coroutines 
that can
receive values as well via a coroutine operator such as "receive". 
Something like:

(define-coro (print-all)
    (while #t
        (let ((x (receive)))   ; receive is a keyword that blocks on an 
expected "resume"
           (print x)))))

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

4
2
6

Scott

Jon Rafkind wrote:
> On 04/05/2010 12:17 PM, Scott McLoughlin wrote:
>> I think the term is "fully asymmetric" coroutines, but please correct
>> me if I'm wrong.  I'm not look for just Python style generators, but
>> a much more robust coroutine implementation.
>>
>> I'm looking for a fairly "canonical, full" coroutine implementation,
>> where a "yield" like operator can work at activation levels other
>> than just the top level, and where a "yield" style operator can
>> function as both a LHS or RHS operator (or two separate operators),
>> facilitating sending values to a coroutine in a "filter chain" style
>> structured program.
>>
>
> I'm not exactly sure what you mean by "work at activation levels other 
> than just the top level" but the scheme/generator library lets you 
> send values back through the `yield' operator.
>
> http://docs.plt-scheme.org/reference/sequences.html?q=generator#(form._((lib._scheme/generator..ss)._generator)) 
>
>
>



Posted on the users mailing list.