[Python-ideas] yield from multiple iterables (was Re: The async API of the future: yield-from)

Nick Coghlan ncoghlan at gmail.com
Sat Oct 20 03:56:45 CEST 2012


On Sat, Oct 20, 2012 at 10:50 AM, Greg Ewing
<greg.ewing at canterbury.ac.nz> wrote:
> Christian Tismer wrote:
>>
>> Actually I would like to have a python context where it gets into
>> "async mode" and interprets all functions defined in that mode as
>> generators.
>
>
> That sounds somewhat similar to another idea I proposed a while
> ago:
>
> There would be a special kind of function called a "cofunction",
> that you define using "codef" instead of "def". A cofunction
> is essentially a generator, but with a special property: when
> one cofunction calls another, the call is implicitly made as
> a "yield from" call.
>
> This scheme wouldn't be completely transparent, since the
> cofunctions have to be defined in a special way. But the calls
> would look like ordinary calls.

Please don't lose sight of the fact that yield-based suspension points
looking like something other than an ordinary function call is a
*feature*, not a bug.

The idea is that the flow control, especially the fact that "other
code may run here, so the world may have changed before we get to the
next expression", is visible *locally* in each function, rather than
relying on global knowledge of which calls may lead to a task switch.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia



More information about the Python-ideas mailing list