question about generators

greg greg at cosc.canterbury.ac.nz
Sun Aug 18 06:46:58 EDT 2002


Tim Peters wrote:
> 
> > -- that is, the one Andrew Koenig was adopting when he didn't
> > immediately see the need for the "for...yield" loop.
> 
> Andrew's example "fails" in the same way if code in Icon, so this particular
> example isn't helpful to your point (in Icon he would need to plop the
> recursive call into an explicit "suspend" control structure to get the
> example to work).

Yes, that's true. But the equivalent to that in Python would
be "yield f()", which doesn't work either (and was one of the
things he tried, if I remember correctly).

> (btw, in another message you seem to
> assume meanings for "up" and "down" that are the reverse of most-common
> usage:  IME most people seem to think of callees as returning "up" to their
> callers;

Which is the point I was rather provocatively trying to
make! I don't know how other people deal with it, but
for me the key to understanding Icon control flow is
to think of "suspend" as a form of call rather than
a form of return. It's equivalent to a call with an
implicit continuation passed down.

Or at least that's what my memory says from when I
played with Icon quite a few years ago. I may be
mis-remembering some of the details -- perhaps I
should go away and refresh my knowledge before saying
any more!

> I'm acutely aware of this because the idea of a stack "growing
> down" is repugnant to my sense of beauty too <wink>).

Hmmm, yes, the stack metaphor does suggest upward growth.
But we talk about "depth" of recursion, not "height" of
recursion!

Ah, well. I never, ever claim to be consistent. :-)

Greg



More information about the Python-list mailing list