[Python-Dev] PEP 342 suggestion: start(), __call__() and unwind_call() methods
Guido van Rossum
guido at python.org
Sat Oct 8 23:29:21 CEST 2005
On 10/7/05, Piet Delport <pjd at satori.za.net> wrote:
> Earlier this week, i proposed legalizing "return Result" inside a generator,
> and making it act like "raise StopIteration( Result )", for exactly this reason.
> IMHO, this is an elegant and straightforward extension of the current
> semantics of returns inside generators, and is the final step toward making
> generator-based concurrent tasks look just like the equivalent synchronous
> code (with the only difference, more-or-less, being the need for appropriate
> "yield" keywords, and a task runner/scheduler loop).
> This change would make a huge difference to the practical usability of these
> generator-based tasks. I think they're much less likely to catch on if you
> have to write "raise StopIteration( Result )" (or "_return( Result )") all the
>  a.k.a. coroutines, which i don't think is an accurate name, anymore.
Before we do this I'd like to see you show some programming examples
that show how this would be used. I'm having a hard time understanding
where you would need this but I realize I haven't used this paradigm
enough to have a good feel for it, so I'm open for examples.
At least this makes more sense than mapping "return X" into "yield X;
return" as someone previously proposed. :)
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-Dev