[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: So, what the heck is a continuation anyway?
Speaking as someone who is not a Scheme expert:
When I was first hearing the term "continuation" coming into use
around MIT, it had a meaning even if call-with-current-continuation
(call/cc, nee "catch") wasn't being used. People spoke of
"continutation-passing style". A continuation was less a new language
construct than a description of a style of using an existing language
construct, namely a "closure".
The basic idea was that a regular program for computing the square of
a number says "accept an argument x, multiply x by x, and return the
result to the caller". The continuation-passing style version says
"accept two arguments x and c, multiply x by x, and call c on the
result (and return the result of c)". In examples like this one, the
object passed as the value of c was referred to as the "continuation".
Hence the relationship between this style of programming, and the
importance of doing an implementation in which tail-calls don't eat up
With call/cc, of course, you can do much more powerful things, but you
could use the word "continuation" properly even if you didn't use
call/cc. I think everyone has been telling you about the more powerful
call/cc stuff because it's so much more exciting and cool and general
Often the continuation objects were closures: functions in a lexical
context, which at a low level means functions with some attached
state. (Functions with attached state bears some kinship to "objects"
in the sense of OOP, and indeed you can build OOP out of closures.)
Lexical scoping had already existed in many languages, such as
ALGOL-60 and PL/I, but in Scheme there was the ability to *return* a
function that was in a lexical context and still keep around the
lexical state. (At the implementation level, this has some kinship to
copying stack frames, although in this case you could say that we're
copying just the data from the stack frames, not the PC's and return
addresses as happens in the call/cc scenarios.)