extending yield's functionality

Terry Reedy tjreedy at home.com
Fri Nov 2 10:18:49 EST 2001


"Eyal Lotem" <eyal at hyperroll.com> wrote in message
news:3be2b616 at news.bezeqint.net...
> I was excited to find out about the new yield functionality, of
generator
> functions, that will be formally in 2.3
>
> I wanted to ask if its possible to have yield receive some more
information
> from the caller, between the yield stages.
>
> An example syntax to implement this could look like:
>
> >>> def a():
> ...     print "Hello"
> ...     b=yield 1
> ...     yield b*2
> ...     yield 3
>
> >>> gen = a()
> >>> gen.next()
> 1
> >>> gen.next(3)
> 6
> >>> gen.next()
> 3

Yield is a statement.  You are trying to use it as an expression.
Will not work, ever, as Python is currently designed.

I believe you are trying to turn yield into a continuation function.
I believe you can do what you want with the Stackless version of
Python, which has a continuation module.
http://stackless.com/research/stackless/

Terry J. Reedy






More information about the Python-list mailing list