[Python-ideas] Yield-From Example 2: Scheduler
Guido van Rossum
guido at python.org
Fri Feb 20 02:47:03 CET 2009
On Thu, Feb 19, 2009 at 5:33 PM, Adam Olsen <rhamph at gmail.com> wrote:
> On Thu, Feb 19, 2009 at 6:04 PM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
>> So there perhaps isn't a very strong case for using 'yield
>> from' in a scheduler setting. However it still illustrates
>> the utility of being able to return a value from a generator,
>> since otherwise you would either have to explicitly raise
>> the StopIteration or resort to some convention such as
>> yield Call(g)/yield Return(x).
> If you can propose semantics for return that don't risk silently
> eating values then I'll at least gives -0. Until then I'm -1.
Can you explain why you feel so strongly about this? As has been
pointed out, returned values are routinely ignored in Python, it is
not an error.
>> In a wider setting, I still think there is benefit in
>> being able to abstract out pieces of generator code
>> without needing to have a special driver.
> Microthreads need the special driver anyway, to handle all the other
> kinds of resources.
I consider "yield from A" *primarily* a shorthand with (optimization
potential) for the oft-repeated clause
for x in A:
Given that this is a useful thing to have anyways, we might as well
give it subtle extra semantics for pass-through and returning values.
After all that is what .send(), .throw() and .close() already do for
generators: most generators don't use these, but they allow certan
advanced things to be built out of generators with more ease and
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-ideas