lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 12/19/08, Diego Nehab <diego@tecgraf.puc-rio.br> wrote:
> Hi,
>
>
> > Now I am reading Diego Nehab's gem on "Filters, Sources, Sinks and Pumps".
> > To my surprise he does not mention coroutines. I think coroutines with
> > their "yield" and "resume" are great mechanism to implement filters
> > and filter chains. They provide an easy and natural way to maintain
> > filter context while processing chunks of data. Also coroutines all
> > but eliminate (or rather hide) need for "pumps".
> > Is there any specific reason they are left out of this gem??
> >
>
>  The original implementation actually used coroutines for the
>  filter chains. Unfortunately, this caused the library to
>  interfere poorly with pcall(), and some users complained.
>  The implementation of the smtp.message() function used as an
>  example the end of the Gem does use coroutines.
>
>  As to the relationship between pumps and coroutines, would
>  you mind clarifying?
>
>  Kind regards,
>  Diego

Diego,
thanks for your reply!

I think that with coroutines you do not need an explicit pump. For
example, in PiL2   Listing 9.1 (page 78)  "pumping loops" are part of
producer, consumer and filter.

Also, with coroutines one can do multi-rate processing when, for
example, filter_1 consumes two chunks of its input to generate one
chunk of output that it passes to filter_2 (in Digital Signal
Processing these things are fairly common)

Best regards,
--Leo--