[Python-ideas] Cofunctions - A New Protocol

Terry Reedy tjreedy at udel.edu
Wed Nov 2 23:34:55 CET 2011


On 11/2/2011 5:44 AM, Greg Ewing wrote:
> Terry Reedy wrote:
>
>> Is this really needed? The presence of 'coyield' signals 'cofunction',
>> just as 'yield' signals 'generator'.
>
> The 'coyield' doesn't have to be directly in that function,
> it could be in something called by that function, any number
> of levels deep.
>
> However, it's since occurred to me that 'coyield' doesn't have
> to be a keyword, it could be a built-in cofunction.

My *feeling* is that 'codef' and 'coyield' are a bit ugly, so that
a) they may hardly be used in extand code, and would be 'safe' to use as 
keywords, but
b) I would not like to see them as keywords ;-).

This is aside from thinking that the relative smallness of Python's 
keyword list is a *feature*.

>>> * A cofunction can only be called from the body of another cofunction,
>>> not in
>>> any other context.
>>
>> Except that an initial 'call' from a coroutine.resume is needed to get
>> the first cofunction started ;-).
>
> Yes, but that's not done using the normal call syntax, which
> is what I'm talking about there

I understood that,

> (that could perhaps be made clearer).

but the sentence, taken in isolation, does raise the bootstrap issue.
So from an editorial viewpoint, I suggested the short addition.

-- 
Terry Jan Reedy




More information about the Python-ideas mailing list