[squeak-dev] Generators in Smalltalk?

Andreas Raab andreas.raab at gmx.de
Wed Feb 10 05:27:36 UTC 2010


Folks -

One thing I really like about Python is Generators 
(http://docs.python.org/tutorial/classes.html#generators). They allow 
code to provide a stream (iterator) interface where it's not easy to 
provide the interface explicitly. I.e., it would allow one to provide a 
stream interface to an arbitrary computation like:

gen := Generator on: [:yield| 3 to: 1 by: -1 do:[:i| yield value: i]].
gen next. "=>3"
gen next. "=>2"
gen next. "=>1"
gen next. "=>nil"

This *ought* to be really simple to do in Smalltalk by using blocks and 
some voodoo in the execution engine. Has anyone ever done that?

Cheers,
   - Andreas



More information about the Squeak-dev mailing list