Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: (Perl6) Groking Continuations

by John M. Dlugosz (Monsignor)
on Apr 10, 2003 at 17:52 UTC ( #249694=note: print w/ replies, xml ) Need Help??

in reply to (Perl6) Groking Continuations

The interesting part about Perl and Prolog and Continuations... oh my! is that the variables are put back to what they were after performing the continuation.

That is, given two constructs x and y, imply x, y, xx where xx is implicit in x and is to be done after y. This is straightforward if y is a closure passed to a function x.

But here is an idea to help eliminate so many (nested) closures.

Have the Unify leave behind an object that goes out of scope to perform xx. As a first cut, that would look like this:

{ # extra scope (my $nameless= unify ($var, "frank")) && print "This is done if var unified with frank."; } # unbinding takes place here.
It still needs too much extra syntax, but the point is that you don't need a closure, and can easily have more than one thing to do inside the scope of the unification, and don't need an exception to indicate success/failure and get back to ordinary procedural code.

In Perl 6, the DESTROY can't be relied upon to be called at the close brace, but a function can add exit actions to the callers scope so that works just as well and avoids the need for $nameless and extra parens.

In C++, which doesn't have closures, you can't declare the variable inside the parens but you don't need to give it a name either if the actions are joined together with commas or &&'s, since a temporary will be destructed at the end of the complete statement containing it.

In C#, there is no mechanism for prompt destruction actions to be called. The scoped lock is built-in and a similar mechanism can't be written within the language (a symptom that it's incomplete).


Comment on Re: (Perl6) Groking Continuations
Select or Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (12)
As of 2014-09-16 14:33 GMT
Find Nodes?
    Voting Booth?

    How do you remember the number of days in each month?

    Results (31 votes), past polls