Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Re: Re: (Perl6) Groking Continuations

by andrewc (Acolyte)
on Apr 11, 2003 at 16:49 UTC ( #249925=note: print w/ replies, xml ) Need Help??


in reply to Re: Re: (Perl6) Groking Continuations
in thread (Perl6) Groking Continuations

Is the right answer. It's not a real continuation because squirreling away a copy of the sub-reference $fred in, say, a package-global variable $Jane and calling $Jane later doesn't do what a real call-cc would allow you to do.

use vars qw{$Jane}; print call_cc { my $fred = shift; $Jane = $fred; # Squirrel away a reference $fred->(42); 64; #NOTREACHED }; print "\n"; # And then call it later, outside the call_cc block... $Jane->(101); #bang.

Results in... you guessed it, an uncaught exception. So it's just an ersatz call-cc.

Funnily enough, call-cc is used in Scheme-like languages a lot for early exits from deep/non-deterministic recursions despite also having a try/catch-style mechanism.


Comment on Re: Re: Re: (Perl6) Groking Continuations
Download Code
Re: Re: Re: Re: (Perl6) Groking Continuations
by John M. Dlugosz (Monsignor) on Apr 11, 2003 at 21:49 UTC
    So the (real) continuation (saved in a global variable) could be called even after the body of call_cc returned?

    I see. If the function call activation frames are treated just like everything else, and there is no special action for "going out of scope", keeping a live reference to it is just like any other closure.

    In Perl 6 we'll have to watch it because of the mechanism for having block-exit code in a finally clause or added dynamically by a caller. What would that do, if one can exit more times than enter?! (I have some ideas of what it should mean, but that's for another thread)

    —John

      What it does is complicate things rather a lot. Continuations are an old, old language feature. Unfortunately many folks doing language work didn't think about then when new language features were developed, so there are things which may not necessarily play well with continuations. They'll work, but may not be an optimal combination.

      In the block exit case, finally clauses will be executed each block exit, which may be somewhat surprising, but not fundamentally an issue. The bigger issue is with things like local/temp/hpyothetical variables.

        So you could have it both ways: the finally block is done every time, and the restore code on a temp variable is done only when it's gone for good?

        But, I think many C++ programmers think of using the former for the purpose of the latter. Especially any code that wants to undo/fixate things by playing with the caller's blocks (as mentioned in earlier discussions) it needs to be clear that setting up something triggered when a variable goes out of scope (e.g. restore from a temp) is not the same as code that's simply inserted just before the close brace of that scope. Earlier, your comments about doing without prompt destruction made me think that we would indeed be using the "finally"-like mechanism for that purpose.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2014-08-20 05:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (105 votes), past polls