zuzu wrote: > On Fri, 27 Aug 2004 05:20:54 +0900, Martin DeMello > <martindemello / yahoo.com> wrote: > >> >>Michael Neumann <mneumann / ntecs.de> wrote: >> >>>zuzu wrote: >>> >>>>can anyone help me decode the following python example using >>>>generators into The Ruby Way using closures? >>> >>>I'm sure the Ruby version must be human-readable... maybe you can >>>describe in short words, what the Python example tries to achive? >>> >>>You might have a look at generator.rb which ships with Ruby and >>>implements generators or "streams" with continuations. >> >>And possibly at http://redshift.sourceforge.net/enum/pipe.html >> >>martin >> >> > > > this looks quite straight-forward, thank you. as with Generator, i've > long suspected this would involve some inherit tweaking of Enumerable, > and all the implementations of this genre seem to do just that. > > in the quote below, this is basically "lazy evaluation", right? > (which i think is "by definition" with asynchronous continuations > rather than synchronous returns.) > I guess it's lazy evaluation, in the sense that no intermediate array is generated. The upstream iteration step happens only when the downstream iteration step asks for the next object. Note that this #pipe method has the advantage of not having the (constant time) overhead of creating a continuation, but it has the disadvantage of being an internal (did I get that right?) iterator, just like #each or any other of the usual Enumerable methods. Oddly, I wrote this code several years ago, but have never used it for some reason. I have to thank Martin for even remembering that it existed.