[Python-ideas] x=(yield from) confusion [was:Yet another alternative name for yield-from]

Jacob Holm jh at improva.dk
Fri Apr 3 19:47:19 CEST 2009


Jim Jewett wrote:
> It looks to me like it returns (or yields) the running average either way.
>   
That is because Nick has mangled my beautiful example - sorry Nick :)

You can see my original example at:

http://mail.python.org/pipermail/python-ideas/2009-April/003841.html

and a few arguments why I think it is better at:

http://mail.python.org/pipermail/python-ideas/2009-April/003847.html

> I see a reason to send in a sentinel value, saying "Don't update the
> average, just tell me the current value."
>
> I don't see why that sentinel has to terminate the generator, nor do I
> see why that final average has to be returned rather than yielded.
>   

Yielding the current value on each send was not part of the original 
example because I was thinking in terms of well-behaved coroutines as 
described in http://dabeaz.com/coroutines/. I agree that it makes sense 
for running averages, but it is not that hard to come up with similar 
examples where the intermediate state is not really useful and/or may be 
expensive to compute.

The reason for closing would be that once you have computed the final 
result, you want whatever resources the coroutine is using to be freed. 
Since only the final result is assumed to be useful, it makes perfect 
sense to close the coroutine at the same time as you are requesting the 
final result.

- Jacob



More information about the Python-ideas mailing list