[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: generators/coroutines vs. lazy lists
> Is there a semantic or ease-of-use distinction between using
> coroutines to handle iteration, as in Icon, and using sequences with
> delayed evaluation, as in section 3.5 of _Structure and Interpretation
> of Computer Programs_?
> == Seth Gordon == email@example.com == http://ropine.com/ == std. disclaimer ==
Are coroutines in Icon substantially the same as
coroutines in other languages (Modula 2, call/cc-based
implementations in Scheme)?
If so, I'd say streams are easier, or at least more
declarative, for a special but important type of
problem: collecting generated results. They provide
the collection in a form that the user doesn't have to
take extraordinary care to distinguish from their usual
lists. The collection holds many, possibly infinite,
related computations, all the while making a
backstage nod to the physical infeasibility of
doing all those computations at once or even ever.
Streams can therefore be quite appealing as an
almost-mathematical notation -- they model the
dot-dot-dot of math textbooks. That is nice.
Coroutines need more commitment from the user qua
programmer, but can also be used for much more than
just generator procedures. You can do preemptive
multitasking with them, which I think is how
Modula 2 sold them.
Apologies if I'm saying too-obvious things here. The
augustness of this crowd gives me paws ^w pause.
I personally found these usability distinctions quite
neat when I first encountered streams and coroutines,
and still do.