[Python-Dev] Simple coroutines?
Daniel Bickett
dbickett at gmail.com
Tue Aug 24 13:45:13 CEST 2004
On Tue, 24 Aug 2004 17:57:18 +1200, Greg Ewing
<greg at cosc.canterbury.ac.nz> wrote:
> > My comment about "coroutines" was more that Guido previously
> > expressed distaste for adding such a communication mechanism to
> > generators as abusing the concept of a generator just being a way to
> > implement complex iterators.
>
> This makes me think that maybe we want another kind of object, similar
> to a generator, but designed to be used for side effects rather than
> to produce values.
>
> For want of a better term, let's call it a "cooperator" (so it ends in
> "ator" like "generator" :-). Actually there will be two objects, a
> cooperator-function (analogous to a generator-function) and a
> cooperator-instance (analogous to a generator-iterator).
>
> Calling a cooperator-function will return a cooperator-instance, which
> will obey the cooperator protocol. This protocol consists of a single
> function run(), which causes the cooperator-instance to perform some
> amount of work and then stop. If there is more work remaining to be
> done, run() returns a true value, otherwise it returns a false value.
Tell me if I'm missing something here, but with the exception of your
two introductory keywords (a subject I thought was supposed to be
sacred, with the intention of keeping the amount of keywords as small
as possible,) how much difference is there to generators? Are you
saying the run() method, after having been called initially, will
return a value indicative of the cooperator's business when called
again?
It seems like a similar feat could be achieved with custom generators
and boolean yield statements.
Daniel Bickett
More information about the Python-Dev
mailing list