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).


In reply to Re: (Perl6) Groking Continuations by John M. Dlugosz
in thread (Perl6) Groking Continuations by crenz

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":