On Dec 8, 2006, at 6:45 PM, Bob Rogers wrote:
From: "Will Coleda" <[EMAIL PROTECTED]>
Date: Fri, 08 Dec 2006 16:00:37 -0500
Given the current :method and .yield implementations . . .
. . .
Which is unsurprising given the current implementation. Is this
desired
behavior, though?
This does not work right for nonmethods either. For normal subs, you
have to find the sub and clone it, and then use that as the Coroutine.
For methods, this would amount to creating a new method per instance,
which is absurd.
I can work around this by storing an attribute on the class
which keeps my
counter in the instance and then retrieving it with getattribute
in the
loop, insuring that the state is pulled from the object instead
of the
registers in the coroutine/method whenever the coroutine resumes.
If you can do that, then you don't really need a Coroutine, do
you? But
if you really can't do that, you might consider Parrot::Coroutine.
True. At that point the yield is pretty useless. =)
Or we could have yield somehow be instance specific.
The real fix is to build Coroutine on Continuation instead of Sub.
That
would still require changing your method to create a Coroutine object
and (I assume) store it in the instance. But that might be what you
want in any case.
Perhaps the right thing would be clearer if you posted a fuller
example of what you are trying to do?
-- Bob Rogers
http://rgrjr.dyndns.org/
I'm attempting to implement the 'Range' object (and other lazy lists)
for perl6, using a coroutine to generate the next value in the range.
At the moment, all instantiations of the range object share the
coroutine for generating their value.
I don't have to use coroutines here, but if I can, I think it'll make
the implementation easier.
--
Will "Coke" Coleda
[EMAIL PROTECTED]