Continuation

A term from functional programming where a function is used to capture the whole of the rest of the computation from a specific point in the lexical scope. It can be seen as a function which also has a side effect, i.e. full replacement of the current evaluation context with another one. A continuation also accepts a parameter and functionally behaves as an identity, with the caveat that the produced value will be used in the context the continuation itself sets up. As an example, in a LISP-like language if c is a continuation storing the context (+ 3 []), the evaluation of (- 5 (c 2)) produces (+ 3 2). Let us suppose that the evaluation strategy of the language selects the redex (c 2) to be evaluated. In first place, the evaluation context of the redex (- 5 []) is replaced with that stored in the continuation (+ 3 []). In second place the functional evaluation of (c 2) is performed. We told that a continuation functionally behaves as an identity, and therefore the value 2 is produced. This value is put back in the evaluation context, which now is (+ 3 []), and the resulting expression (+ 3 2) is evaluated.

Continuations as objects are powerful in that passing them around as arguments allows implementing very flexible control-flow structures; Essentially, they are high-level goto's. Continuations in most languages have a security flaw, however, since they are not implemented with linear usage restrictions: A continuation may be freely (re-)evaluated by any part of the system that receives a reference to it.

There is a means of implementing functional-style language using continuations as a low-level control-flow model, and a standard means of embedding normal lexical scoping in terms of it, called continuation-passing style.


This page is linked from: Continuation-Passing Style   FDScript   Reification   Ruby   Sigil   Thread   Tube