[Python-ideas] Cofunctions - Back to Basics

Greg Ewing greg.ewing at canterbury.ac.nz
Sat Oct 29 08:40:38 CEST 2011


Steven D'Aprano wrote:

> One specific thing I took out of this is that only the main body of a 
> Python generator can yield.
> 
> I can see how that would be a difficulty, particularly when you move 
> away from simple generators yielding values to coroutines that accept 
> values, but isn't that solved by the "yield from" syntax?

Only for limited values of "solved" -- to my mind, it's still
a rather unnatural way to write coroutine code.

Perhaps I should point out that the way I envisage using
generators as lightweight threads, the yields will typically
be neither sending nor receiving values, but simply serving
as suspension points.

If a generator is actually producing values, then the phrase
"yield from" has meaning, but if it's not -- if you're just
using it to calculate a return value or cause a side effect --
it reads like nonsense. Maybe I'm more sensitive to such
considerations than other people, but it bothers me.

-- 
Greg




More information about the Python-ideas mailing list