[Python-Dev] next(arg) was: Anonymous blocks: Thunks or iterators?
Guido van Rossum
gvanrossum at gmail.com
Fri Apr 29 20:00:06 CEST 2005
[Guido van Rossum]
> > One [of many separate ideas in PEP 340] is turning generators
> > into more general coroutines: continue EXPR passes the expression
> > to the iterator's next() method ...
[Jim Jewett]
> I would have been very happy with that a week ago. Seeing the
> specific implementation changed my mind.
>
> The caller shouldn't know what state the generator is in, so the
> passed-in-message will be the same regardless of which yield
> accepts it. Unless I have a single-yield generator, this means
> I end up writing boilerplate code to accept and process the arg
> at each yield. I don't want more boilerplate.
I think your premise is wrong. When necessary (which it usually won't
be) the caller can tell the generator's state from the last thing it
yielded. Coroutines can easily define a protocol based on this if
needed. Anyway, single-yield generators are by far the majority.
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-Dev
mailing list