From: Дамјан Георгиевски on
>> > I'm writing this as a complete newbie (on the issue), so don't be
>> > surprised if it's the stupidest idea ever.
>>
>> > I was wondering if there was ever a discusision in the python
>> > community on a 'raise-yield' kind-of combined expression. I'd like
>> > to know if it was proposed/rejected/discussed/not-decided yet??
>>
>> Recently (ok, several hours ago) I've come up to Greenlets [1] and it
>> seems they implement exactly what I was asking for, in a C
>> extension!!
>>
>> It's too bad that Python doesn't support this by default and many
>> libraries won't make use of it by default. Gevent [2] for example,
>> has to monkey-patch Python's socket, time.sleep and other modules so
>> that things like urllib work with it.
>>
>> I'll continue to read now.
>
> Ah, if I had seen your original post I probably could have pointed you
> to some good reading right away. What you've described is called a
> continuation, and is natively supported by some languages (like
> Scheme). It's usually not done with exceptions, though. In Scheme
> it's a special form that looks like an ordinary function call, but you
> can "return" from the call any number of times.

I thought they were called coroutines?

Anyway, here's the Lua implementation of coroutines. It's basically a
yield but it will return back several frames.

http://lua-users.org/wiki/CoroutinesTutorial


--
дамјан ((( http://damjan.softver.org.mk/ )))

Today we create the legacy of tomorrow.

From: Thomas Jollans on
On 07/06/2010 08:56 PM, Дамјан Георгиевски wrote:
>>>> I'm writing this as a complete newbie (on the issue), so don't be
>>>> surprised if it's the stupidest idea ever.
>>>
>>>> I was wondering if there was ever a discusision in the python
>>>> community on a 'raise-yield' kind-of combined expression. I'd like
>>>> to know if it was proposed/rejected/discussed/not-decided yet??
>>>
>>> Recently (ok, several hours ago) I've come up to Greenlets [1] and it
>>> seems they implement exactly what I was asking for, in a C
>>> extension!!
>>>
>>> It's too bad that Python doesn't support this by default and many
>>> libraries won't make use of it by default. Gevent [2] for example,
>>> has to monkey-patch Python's socket, time.sleep and other modules so
>>> that things like urllib work with it.
>>>
>>> I'll continue to read now.
>>
>> Ah, if I had seen your original post I probably could have pointed you
>> to some good reading right away. What you've described is called a
>> continuation, and is natively supported by some languages (like
>> Scheme). It's usually not done with exceptions, though. In Scheme
>> it's a special form that looks like an ordinary function call, but you
>> can "return" from the call any number of times.
>
> I thought they were called coroutines?

The scheme call-with-current-continuation facility is a lot more
powerful than python generator-coroutines or, I expect, than whatever it
is that Lua has.

In Python, you can return to a "yield" expression exactly once, then the
code continues, and the state is lost. In Scheme, you can pass the state
around, save it, and return there as often as you want. Kind of
"go-back-to-this-particular-frame-state" as opposed to
"go-back-into-that-(co)routine"

Everything that you can do with the coroutine facilities in languages
like Python, Ruby, and Lua, Scheme's call/cc allows you to do as well.

Thomas