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

Re: Demystifying continuations




Some time back I asked the list "what are continuations?"
and got some help - in particular from Raphael Finkel's
book, "Advanced Programming Language Design", which is
available on the web at

	http://cseng.aw.com/book/related/0,3833,0805311912+20,00.html
	
It's quite readable.  I think that now I have a crude
idea of what continuations are - a continuation is
a "goto with parameters":  as opposed to a function
that returns to its caller, a continuation passes
control to some other function.  It's possible to
have a programming language in which every function
ends in a continuation.

So, when a function that contains a continuation is
invoked, the continuation address (function name)
must also be provided.

For example, a function that processes lists might
contain a continuation that is invoked if one of
the elements in the list is negative.  If none of 
the elements are negative, the function returns
to its caller after processing all elements.
If one element is negative, then control passes to
another function that takes that negative element
as a parameter.

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.
In fact, when in Scheme (for example) call/cc
"returns a continuation" I am not sure what that
means.  Does that mean that if I capture that
continuation, I can invoke it later on, at my leisure?

Kevin Kelleher