[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Demystifying continuations



Kevin Kelleher wrote:

> Now this part is not clear to me:  I think that there
> is no obligation to return to point at which the
> continuation is invoked, although you can.

That's correct, and in fact I think that could be said to be the whole point of continuations - they continue, they don't necessarily return.  Speaking conceptually, or assuming a system based entirely on continuations, "returning" is done, when necessary, by invoking the "return continuation" supplied by the function's caller.

It might help to stop thinking of "returning" as an internal, default operation that you take for granted, and rather imagine that every function is always passed a return continuation which it may or may not choose to use.  "Returning" is just conceptual and syntactic sugar for invoking the return continuation.

That's why continuations are usually taught along with continuation passing style (CPS): it's much easier to grasp the implications of the concept when you invoke all continuations (including return continuations) explicitly, instead of having the language invoke certain otherwise hidden continuations for you.

> In fact, when in Scheme (for example) call/cc
> "returns a continuation" I am not sure what that
> means.  

Call/cc doesn't "return a continuation".  It calls a specified function and provides the current continuation as an argument.

> Does that mean that if I capture that
> continuation, I can invoke it later on, 
> at my leisure?

If you capture a continuation then yes, you can invoke it later on, at your leisure, if the language you're using doesn't impose arbitrary restrictions.  Which is why continuations can give language implementors conniptions...

Anton