http://www.perlmonks.org?node_id=96418


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