And, predictably, that gave me a headache... :-)
--Guido van Rossum (sent from Android phone)
Guido van Rossum wrote:
On Mon, Oct 22, 2012 at 3:33 PM, Greg Ewing <greg.ewing@canterbury.ac.nz> wrote:
It has a broader meaning than the one in Scheme; essentially
it's a synonym for "callback".
(Off-topic:) But does that meaning apply to Scheme? If so, I wish
someone would have told me 15 years ago...
It does, in the sense that a continuation appears to the
Scheme programmer as a callable object.
The connection goes deeper as well. There's a style of
programming called "continuation-passing style", in which
nothing ever returns -- every function is passed another
function to be called with its result. In a language such
as Scheme that supports tail calls, you can use this style
extensively without fear of overflowing the call stack.
You're using this style whenever you chain callbacks
together using Futures or Deferreds. The callbacks don't
return values; instead, each callback arranges for another
callback to be called, passing it the result.
This is also the way monadic I/O works in Haskell. None
of the I/O functions ever return, they just call another
function and pass it the result. A combination of currying
and syntactic sugar is used to hide the fact that you're
passing callbacks -- aka continuations -- around all
over the place.
Now, it turns out that you can define all the semantics
of Scheme, including its continuations, by writing a Scheme
interpreter in Scheme that doesn't itself use Scheme
continuations. You do it by writing the whole interpereter
in continuation-passing style, and it becomes clear that
at that level, the "continuations" are just ordinary
functions, relying on lexical scoping to capture all of the
necessary state.
I guess that was just Steve showing off. :-)
Not really -- to someone with a Scheme or FP background,
it's near-impossible to look at something like a chain
of Deferred callbacks without the word "continuation"
springing to mind. I agree that it's not helpful to
anyone without such a background, however.
--
Greg
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
http://mail.python.org/mailman/listinfo/python-ideas