Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Re: (Perl6) Groking Continuations

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


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

Hmm, I think that's basically a try/catch mechanism. That is, call_cc gives you a block which includes fred. Calling fred will pop out of the whole call_cc block, even if fred was called by a subroutine deeply nested in the calling sequence. That is, it generates a "throw" keyword for you that's specific to this "try" scope. The argument to fred is used to signal exception data back to the point after call_cc, which can use that to distinguish success from failure.

—John


Comment on Re: Re: (Perl6) Groking Continuations
Re: Re: Re: (Perl6) Groking Continuations
by andrewc (Acolyte) on Apr 11, 2003 at 16:49 UTC

    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.

      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.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (13)
As of 2014-08-27 12:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (238 votes), past polls