develooper Front page | perl.perl6.language | Postings from July 2002

Re: Continuations for fun and profit

Thread Previous | Thread Next
From:
Nicholas Clark
Date:
July 8, 2002 14:33
Subject:
Re: Continuations for fun and profit
Message ID:
20020708212405.GD305@Bagpuss.unfortu.net
On Mon, Jul 08, 2002 at 04:54:16PM -0400, Dan Sugalski wrote:
> Pretty simple. (For illustrative purposes) To do that with 
> continuations, it'd look like:
> 
>    $cont = take_continuation();
>    if ($foo) {
>      $foo--;
>      invoke($cont);
>    }
> 
> take_continuation() returns a continuation for the current point (or 
> it could return one for the start of the next statement--either 
> works), and invoke takes a continuation and invokes it. When you 
> invoke a continuation you put the call scratchpads and lexical 
> scratchpads back to the state they were when you took the 
> continuation.

So take_continuation is called once and returns 1 or more times?
(1st return is just after you called it, second and later are for each time
you invoke $cont from somewhere else)

and invoke is goto-on-steroids, and never returns? (except if $cont is duff,
somewhat like the exec system call in Unix only returns on failure)

And everything else is serene and swan-like?

(ie the language gives the appearance of moving smoothly on the surface,
but under water its feet are paddling furiously to implement motion)

Nicholas Clark
-- 
Even better than the real thing:	http://nms-cgi.sourceforge.net/

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About