Continuation
Encyclopedia : C : CO : CON : Continuation
- For other uses, see (disambiguation)}}}.
Continuations are also used in models of computation including the Actor model, process calculi, and the lambda calculus. Steve Russell invented the continuation in his second LISP implementation for the IBM 704, though he did not name it. Christopher Strachey, Christopher P. Wadsworth and John C. Reynolds brought the term continuation into prominence in their work in the field of denotational semantics that makes extensive use of continuations to allow sequential programs to be analysed in terms of functional programming semantics.
Example
In Scheme:
(define theContinuation 0)
(define (test)
(let ((i 0))
(call/cc (lambda (k)
(set! theContinuation k)))
(set! i (+ i 1))
i))
Defines a function test that sets theContinuation to the future execution state of itself:
At one time Gerry Sussman and Drew McDermott thought that using re-invocable continuations (which they called "Hairy Control Structure") was the solution to the AI control structure problems that had originated in Planner. Carl Hewitt et al. developed message passing as an alternative solution in the Actor model. Guy Steele and Gerry Sussman then developed the continuations in Scheme in their attempt to understand the Actor model.
A more limited kind is the escape continuation that may be used to escape the current context to a surrounding one. Many languages which do not explicitly support continuations support exception handling, which is equivalent to escape continuations and can be used for the same purposes. C's
From Wikipedia, the Free Encyclopedia. Original article here. Support Wikipedia by contributing or donating.(test)
i1
(theContinuation)
i2
(theContinuation)
i3
(define anotherContinuation theContinuation)
(test)
i1
(theContinuation)
i2
(anotherContinuation)
i4Programming language support
Many programming languages exhibit such a feature under various names; specifically:setcontext et al. (UNIX System V and GNU libc)callcc0 and callcc1callCC (in module Control.Monad.Cont)Continuationcallcccall/cc (short for call-with-current-continuation)Continuation currentDo:, in most modern Smalltalk environments continuations can be implemented without additional VM support.SMLofNJ.Cont.callccc, the flow control operation for call with current continuationKinds of continuations
Support for continuations varies widely. A programming language supports re-invocable continuations if a continuation may be invoked repeatedly (even after it has already returned). Re-invocable continuations were introduced by Peter J. Landin using his J (for Jump) operator that could transfer the flow of control back into the middle of a procedure invocation. Re-invocable continuations have also been called "re-entrant" in the MzScheme programming language. However this use of the term "re-entrant" is too easily confused with its use in discussions of multithreading.setjmp/longjmp are also equivalent: they can only be used to unwind the stack. Escape continuations can also be used to implement tail-call optimization.Disadvantages
Continuations are the functional expression of the GOTO statement, and the same caveats apply. While they are a sensible option in some special cases, use of continuations can result in code that is difficult to follow. In fact, the esoteric programming language Unlambda includes call-to-current-continuation as one of its features solely because of its resistance to understanding. The external links below illustrate the concept in more detail.See also
External links
References
All text is available under the terms of the GNU Free Documentation License See Wikipedia Copyrights for details.
