Iterators & generators (RE: Real Problems with Python)

Andrew Cooke andrew at andrewcooke.free-online.co.uk
Wed Feb 16 04:30:07 EST 2000


In article <38A96FB1.E7DEA50 at tismer.com>,
  Christian Tismer <tismer at tismer.com> wrote:
> Andrew Cooke wrote:
[...]
> > through some posts on Deja, but there was nothing recent that seemed
to
> > explain what a coroutine actually is - sorry if I've missed
something
> > obvious).
>
> What did you read, actually?
> Here some pointers:
> Homepage:   http://www.tismer.com/research/stackless/
> IPC8 paper: http://www.tismer.com/research/stackless/spcpaper.htm

I read this.  If you read it yourself, trying to remember that once you
did not know what coroutines were, I think you'll see that the text
doesn't contain anything like "A coroutine is...".   Coroutines aren't
even mentioned in the contents.

In turns out (after reading Tim P's code in another pointer you gave)
that all I really wanted to see was something like "coroutines allow
continuations to be used in parallel" or something similar (assuming
I've got it right!).

> Slides:     http://www.tismer.com/research/stackless/spc-sheets.ppt
> The latter gives you a bit of understanding what a continuation is.

I'm afraid these are in some strange format.

Thanks for the info - I'm sorry to waste your time but I do think that
you're so deep into this you may not have realised that

- coroutines are not explicitly defined, as far as I could see.

- noddy examples, while they may give people the wrong impression about
the power of the system, do let newbies understand what the basics are
(I am sure coroutines are not the only concept in computing that is more
powerful than a noddy example - I seem to be able to use those other
concepts in deep ways despite being exposed to equivalent examples in my
youth).

> > Also, comp.lang.lisp is currently dissing continuations.  Would that
be
> > because the alternative is to pass the code that will process the
node
> > into the iterator as a (first class) function?  Obviously, in this
case,
> > yes, but is that true in general (are there examples where
continuations
> > or coroutines make something possible that really is tricky to do in
> > other ways)?

Answering my own question here - there is an obvious advantage in the
iterator approach when iterating over several data structures in
parallel.  That's a trivial (now) counterexample to my suggestion (it
struck me at the time that passing in a function or returning with from
a coroutine were like mirror images of each other - parallel data shows
how this breaks down).

> An iterator is quite an easy thing, and it can be implemented
> without continuations rather easily. Continuations cover problems
> of another order of magnitude. It is due to too simple examples
> that everybody thinks that coroutines and generators are the
> only target. Continuations can express any kind of control flow,
> and they can model iterators, coroutines and generators easily.
> The opposite is not true!
>
> I know this isn't enough to convince you, but at the time I have
> no chance. I need to build some very good demo applications
> which use continuations without exposing them to the user,
> and this is admittedly difficult.

Maybe my post gave the impression that I was doubtful or needed
convincing.  I don't think either is true - I was simply curious.

Thanks for all the info,
Andrew

PS Another point in favour of noddy examples - Tim's iterator finally
made clear to me how a Prolog implementation worked in Lisp.  Hardly a
case of dumbing down....


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list