Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Coroutine reset functionality?

5 views
Skip to first unread message

Klaas-Jan Stol

unread,
May 29, 2006, 4:54:24 PM5/29/06
to perl6-i...@perl.org
Hi,
I couldn't find any functionality to reset a coroutine. Sometimes you want
to reset a coroutine, so it starts at the beginning of the sub body, but
there doesn't seem to be any method to do that. Am I overlooking something?

Thanks,
klaas-jan

Klaas-Jan Stol

unread,
May 29, 2006, 5:24:20 PM5/29/06
to Elizabeth Mattijsen, perl6-i...@perl.org
I was thinking of just a method on the Coroutine PMC so you could do

.sub some_global_coroutine
.yield(1)
.yield(2)
.yield(3)
.yield(4)
.yield(5)
.end

.local pmc mycoro
# create the coroutine
mycoro = global 'some_global_coroutine'
mycoro = clonoe mycoro

.local pmc corresult
# call it a few times
corresult = mycoro() # 1
corresult = mycoro() # 2
corresult = mycoro() # 3
mycoro."reset"() # reset the coroutine
corresult = mycoro() # 1 again (not 4)

But maybe this was already possible, I don't know. I'm not familiar with the
implementation specifics of a Coroutine, but it seems to me it shouldn't be
too hard.

Kind regards,
klaas-jan

On 5/29/06, Elizabeth Mattijsen <l...@dijkmat.nl> wrote:

> Good point.
>
> Essentially you would be removing the continuation context of that
> subroutine / method.
>
> A method on a method maybe?
>
> foo.reset( bar => 1 );
>
> comes to mind?
>
>
> Suggestions? Comments?
>
>
> Liz
>

Elizabeth Mattijsen

unread,
May 29, 2006, 5:11:08 PM5/29/06
to Klaas-Jan Stol, perl6-i...@perl.org
At 11:04 PM +0200 5/29/06, Klaas-Jan Stol wrote:

Good point.

Leopold Toetsch

unread,
May 30, 2006, 4:49:38 AM5/30/06
to Klaas-Jan Stol, Perl6 Internals

On May 29, 2006, at 23:24, Klaas-Jan Stol wrote:

> mycoro."reset"() # reset the coroutine
> corresult = mycoro() # 1 again (not 4)
>
> But maybe this was already possible, I don't know.

Not yet. But it should be simple and straightforward to implement it.
During the first invoke() the coroutine is allocating its context stuff
(co->ctx, ctx->lex_pad, ctx->current_cont). .reset() would just free
these items and set C< co->ctx > to NULL.

leo

0 new messages