On Tue, Jun 29, 2004 at 05:31:29PM -0600, Luke Palmer wrote:
> Oh no! Someone doesn't understand continuations! How could this
> happen?! :-)
>
> You need two things to bring the state of the process back to an earlier
> state: undo and continuations. People say continuations are like time
> traveling; I like to put it this way:
>
> Say you're in the kitchen in front of the refrigerator, thinking about a
> sandwitch. You take a continuation right there and stick it in your
> pocket. Then you get some turkey and bread out of the refrigerator and
> make yourself a sandwitch, which is now sitting on the counter. You
> invoke the continuation in your pocket, and you find yourself standing
> in front of the refrigerator again, thinking about a sandwitch. But
> fortunately, there's a sandwitch on the counter, and all the materials
> used to make it are gone. So you eat it. :-)
Urf. Okay, put me on the list as "someone who thought he understood
continuations at least somewhat but obviously didn't have a clue."
I was under the impression that a continuation was the entire state of
the program at that point and that, when invoked, it overwrites the
current state with the saved one. Therefore, if you invoke a
continuation, you are resetting everything to the when it was when the
continuation was taken. So external changes (the fact that you wrote
to a file) will remain, but internal changes (the fact that you
assigned 7 to $foo) will be undone. I'm not sure how some of the edge
cases (where things are partially internal and partially external) are
supposed to work out, for example:
$dbh = connect_to_db_and_prepare_fetch_call();
# save continuation here
close_connection_to_db($dbh);
# invoke saved continuation here
$dbh->fetch_row(); # DB has closed connection so this fails.
Needless to say, I have never worked with continuations myself, just
studied them very briefly in college (a long time ago).
> A continuation doesn't save data. It's just a closure that closes over
> the execution stack (and any lexicals associated with it; thus the "I
> want a sandwitch" thought). If things change between the taking and
> invoking of the continuation, those things remain changed after
> invoking.
Well, at least that's a nice simple explanation. Why couldn't anyone
have explained it to me that way before? Unfortunately, it means that
continuations are a lot less useful than I thought they were. :<
How do continuations and threads interact? When you take a cont, are
you taking it only within the current thread? Or does it snapshot all
threads in the process?
--Dks