[Python-Dev] Re: anonymous blocks

Phillip J. Eby pje at telecommunity.com
Mon Apr 25 05:32:30 CEST 2005


At 04:57 PM 4/24/05 -0700, Guido van Rossum wrote:
>So a block could return a value to the generator using a return
>statement; the generator can catch this by catching ReturnFlow.
>(Syntactic sugar could be "VAR = yield ..." like in Ruby.)

[uncontrolled drooling, followed by much rejoicing]

If this were available to generators in general, you could untwist 
Twisted.  I'm basically simulating this sort of exception/value passing in 
peak.events to do exactly that, except I have to do:

     yield somethingBlocking(); result=events.resume()

where events.resume() magically receives a value or exception from outside 
the generator and either returns or raises it.  If next()-with-argument and 
next_ex() are available normally on generators, this would allow you to 
simulate co-routines without the events.resume() magic; the above would 
simply read:

     result = yield somethingBlocking()

The rest of the peak.events coroutine simulation would remain around to 
manage the generator stack and scheduling, but the syntax would be cleaner 
and the operation of it entirely unmagical.



More information about the Python-Dev mailing list