"Levente" == Levente Uzonyi leves@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.