[Python-Dev] Simple generators, round 2

Tim Peters tim.one@home.com
Sun, 25 Mar 2001 01:11:58 -0500


[Tim]
>> If you give me a coroutine program, and let me add a "control
>> loop", ...

[Neil Schemenauer]
> This is exactly what I started doing when I was trying to rewrite
> your Coroutine.py module to use generators.

Ya, I figured as much -- for a Canadian, you don't drool much <wink>.

>> A. Simple to implement in CPython without threads, and at least
>>    possible likewise even for Jython.

> I'm not sure about Jython.  The sys._getframe(), frame.suspend(),
> and frame.resume() low level interface is nice.  I think Jython
> must know which frames are going to be suspended at compile time.

Yes, Samuele said as much.  My belief is that generators don't become *truly*
pleasant unless "yield" ("suspend"; whatever) is made a new statement type.
Then Jython knows exactly where yields can occur.  As in CLU (but not Icon),
it would also be fine by me if routines *used* as generators also needed to
be explicitly marked as such (this is a non-issue in Icon because *every*
Icon expression "is a generator" -- there is no other kind of procedure
there).

> That makes it hard to build higher level control abstractions.
> I don't know much about Jython though so maybe there's another way.
> In any case it should be possible to use threads to implement
> some common higher level interfaces.

What I'm wondering is whether I care <0.4 wink>.  I agreed with you, e.g.,
that your squasher example was more pleasant to read using generators than in
its original coroutine form.  People who want to invent brand new control
structures will be happier with Scheme anyway.