A continuation implements (reifies) the program control state, i.e. the continuation is a data structure that represents the computational process at a given point in the process's execution; the created data structure can be accessed by the programming language, instead of being hidden in the runtime environment.
As part of a formulation for an Algol 60 preprocessor, he called for a transformation of proper procedures into continuation-passing style,[1] though he did not use this name, and his intention was to simplify a program and thus make its result more clear.
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.
True first-class continuations do not save program data – unlike a process image – only the execution context.
These models rely on programmers or semantics engineers to write mathematical functions in the so-called continuation-passing style.
Functional programmers who write their programs in continuation-passing style gain the expressive power to manipulate the flow of control in arbitrary ways.
The cost is that they must maintain the invariants of control and continuations by hand, which can be a highly complex undertaking (but see 'continuation-passing style' below).
Continuations can provide elegant solutions to some difficult high-level problems, like programming a web server that supports multiple pages, accessed by the use of the forward and back buttons and by following links.
Other more complex examples include coroutines in Simula 67, Lua, and Perl; tasklets in Stackless Python; generators in Icon and Python; continuations in Scala (starting in 2.8); fibers in Ruby (starting in 1.9.1); the backtracking mechanism in Prolog; monads in functional programming; and threads.
The Scheme programming language includes the control operator call-with-current-continuation (abbreviated as: call/cc) with which a Scheme program can manipulate the flow of control: Using the above, the following code block defines a function test that sets the-continuation to the future execution state of itself: For a gentler introduction to this mechanism, see call-with-current-continuation.
Most programming languages use a call stack for storing the variables needed because it allows for fast and simple allocating and automatic deallocation of memory.
Other programming languages use a heap for this, which allows for flexibility at a higher cost for allocating and deallocating memory.
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.
[10] While they are a sensible option in some special cases such as web programming, use of continuations can result in code that is difficult to follow.
In fact, the esoteric programming language Unlambda includes call-with-current-continuation as one of its features solely because expressions involving it "tend to be hopelessly difficult to track down".
[12] Barker argued that this hypothesis could be used to explain phenomena such as duality of NP meaning (e.g., the fact that the QNP "everyone" behaves very differently from the non-quantificational noun phrase "Bob" in contributing towards the meaning of a sentence like "Alice sees [Bob/everyone]"), scope displacement (e.g., that "a raindrop fell on every car" is interpreted typically as
He also observed that this idea is in a way just a natural extension of Richard Montague's approach in "The Proper Treatment of Quantification in Ordinary English" (PTQ), writing that "with the benefit of hindsight, a limited form of continuation-passing is clearly discernible at the core of Montague’s (1973) PTQ treatment of NPs as generalized quantifiers".
The extent to which continuations can be used to explain other general phenomena in natural language is a topic of current research.