On Mon, Aug 07, 2000 at 10:50:59PM -0400, Buddha Buck wrote:
> The "back out of a stack frame and later come back to continue it"
> bit is since continuations are first-class values, they can be
> stored. But remember: They represent the -entire- future history of
> the program. That means that:
>
> our $cont;
> sub storeit {
> ($cont) = @_;
> return 0;
> }
> $bar = 'a';
> $num = callcc(\&storeit);
> print "$num$bar";
> $bar++;
> &$cont($num+1) if $num<10;
>
> will print "0a1a2a3a4a5a6a7a8a9a" (and not "0a1b2c3d4e5f6g7h9i" as
> you might think). At the time the continuation is saved, $bar was
> 'a'. (Note: I'm not entirely certain about that... It might print
> 0a1b...). This is the point where people can freak out about the
> effects of continuations. Being able to save the "rest of the
> program" into a variable is not something most people consider.
The above example suggests a stronger type of continuations than I
have in mind for Perl. I am thinking of storing only the call
stack. not the interpreter's global state.
However, being able to do both independently would be nice. The
undocumented C<perl_clone> function in v5.6.0 seems to create an
in-memory copy of the entire execution context. Interestingly, it has
a flag to control whether the stack is copied as well, but no way that
I can see to represent just the stack.
-John