[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: So, what the heck is a continuation anyway?
At 03:11 PM 12/10/2001 -0500, Shriram Krishnamurthi wrote:
>Dan, here's an explanation that should make sense to an assembly hacker:
>
>One simple way to think of a continuation is
>
> It's the stack.
>
>At some point, while my program is running, I look at the stack and
>think, "Hey, this is a useful computation -- maybe I'd like to come
>back and do this later". I "capture" it. Think of that as making a
>copy of the stack.
Sounds like a warped closure. (Or a closure's a warped continuation. Or both)
>Later I say, "Hmm, that was a useful computation -- I'd like to do it
>now". At that point, I use the copied stack.
>
>Scheme asks, why use it only once? Use it as many times as you want.
>So each time I use it, I have to copy it again.
Is the copying fully required, and does anything that happens after the
snapshot's taken affect the snapshot?
For example, if I have:
{
int i = 0;
make_continuation();
print i;
i = 3;
}
Will that print 0 or 3 when the continuation is invoked? And if I invoke
that continuation a second time will it print 0 or 3?
>There are lots of papers on how to implement continuations MUCH more
>efficiently than this, but explaining them won't help you understand
>the operation much more easily.
Given the rather odd internals of Parrot, I'm not sure how much help
they'll be, but I'll dig in once I get a good grip on this.
>So, what's an example of a computation that totters on from stack to
>stack? Think Web programming. See my lecture notes for more:
>
> http://www.cs.brown.edu/courses/cs173/2001/Lectures/
>
>Specifically, the lectures for
>
> 2001-10-01 Web Programming
> 2001-10-03 Converting Programs for the Web
> 2001-10-10-12 Continuations
>
>Don't worry, the parens don't bite. (-:
I've survived the horror that is SelfGOL. (It's a perl program that's
self-replicating, makes other perl programs self-replicating, plays the
game of life, and displays a rotating banner. Without loops. In less than
1200 characters of source) Parens are *nothing* compared to that. :)
Dan
--------------------------------------"it's like this"-------------------
Dan Sugalski even samurai
dan@sidhe.org have teddy bears and even
teddy bears get drunk