[squeak-dev] Re: Generators in Smalltalk?

Randal L. Schwartz merlyn at stonehenge.com
Thu Feb 11 00:59:29 UTC 2010

>>>>> "Levente" == Levente Uzonyi <leves at elte.hu> writes:

Levente> On Wed, 10 Feb 2010, Enrico Spinielli wrote:
>> SICP to the rescue
>> http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-24.html#%_sec_3.5.2

Levente> Well, this is not efficient. It states that it implements the sieve of
Levente> Eratosthenes, but it uses division... A smalltalk equivalent with generators
Levente> would look like this (according to my minimal lisp knowledge):

What you really want is a set of generators that produce
2, 4, 6, 8 ...
3, 6, 9, 12 ...
5, 10, 15, 20, ...

and could efficiently "merge" them in order, so that you could "subtract" that
merge from a generator counting 1..n.  If anything made it past that subtract,
it would become a new sequence generator.

I think I saw this technique in "Higher Order Programming", a book
about using Perl closures to do some really wicked stuff.

Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn at stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

More information about the Squeak-dev mailing list