Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Re: Perl 6 coroutines (RFC 31)

by John M. Dlugosz (Monsignor)
on Jul 13, 2001 at 18:52 UTC ( [id://96418]=note: print w/replies, xml ) Need Help??


in reply to Re: Perl 6 coroutines (RFC 31)
in thread Perl 6 coroutines (RFC 31)

I couldn't follow the continuation lab you mentioned. But I think the idea of a continuation primitive is exactly what we need, and my comments to Tilly earlier on this thread seems to be that.

Specifically, the first yeild returns a continuation object. Use that object to "resume", and it knows exactly which instance you mean. The resume should pass parameters, too. It would re-bind @_ in the function, so the line after yeild could look at that (again) if desired.

The resumer thing could be an object with various members, including call and reset and who knows what else. Or, it could return a function reference and just calling that will resume.

my $next= $container->iterate ('inorder'); while (my $node= $next->()) { ... }
Details: the iterate() function would do set-up and yeild with a token, using another built-in function to generate it. Or it could be a separate statement that creates it and yeilds at once. Then it goes into the traversal loop.

What do you think? —John

Replies are listed 'Best First'.
Re: Re: Re: Perl 6 coroutines (RFC 31)
by MeowChow (Vicar) on Jul 14, 2001 at 08:16 UTC
    The semantics of real continuations are less trivial than that, and they appear (to me, at least) substantially more convoluted when applied to procedural, as opposed to functional languages. What you're describing is still a form of generators, which can be built with continuations and anonymous subs, but doesn't provide the full power of continuations.

    Additionaly, rebinding @_ is most likely a bad idea. There are better ways to pass values through to continuations. Changing your local context somewhat defeats the purpose of continuations to begin with.

       MeowChow                                   
                   s aamecha.s a..a\u$&owag.print
      So how would you do it, in Perl?
        I haven't had much practical experience with continuations, so although I grok the general theory underlying them, I really haven't a clue what a good implementation for Perl would look like :/ Having read a bit more on this topic, it appears as if continuations are a theoretically good, but inefficient way to build the higher-level language constructs.
           MeowChow                                   
                       s aamecha.s a..a\u$&owag.print

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://96418]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-20 07:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found