language-icon Old Web
English
Sign In

Delimited continuation

In programming languages, a delimited continuation, composable continuation or partial continuation, is a 'slice' of a continuation frame that has been reified into a function. Unlike regular continuations, delimited continuations return a value, and thus may be reused and composed. Control delimiters, the basis of delimited continuations, were introduced by Matthias Felleisen in 1988 though early allusions to composable and delimited continuations can be found in Carolyn Talcott's Stanford 1984 dissertation, Felleisen and Friedman's PARL 1987 paper, and Felleisen's 1987 dissertation. In programming languages, a delimited continuation, composable continuation or partial continuation, is a 'slice' of a continuation frame that has been reified into a function. Unlike regular continuations, delimited continuations return a value, and thus may be reused and composed. Control delimiters, the basis of delimited continuations, were introduced by Matthias Felleisen in 1988 though early allusions to composable and delimited continuations can be found in Carolyn Talcott's Stanford 1984 dissertation, Felleisen and Friedman's PARL 1987 paper, and Felleisen's 1987 dissertation. Delimited continuations were first introduced by Felleisen in 1988 with an operator called F {displaystyle {mathcal {F}}} , first introduced in a tech report in 1987, along with a prompt construct # {displaystyle #} . The operator was designed to be a generalization of control operators that had been described in the literature such as call/cc from Scheme, ISWIM's J operator, John C. Reynolds' escape operator, and others. Subsequently, many competing delimited control operators were invented by the programming languages research community such as prompt and control, shift and reset, cupto, fcontrol, and others. Various operators for delimited continuations have been proposed in the research literature. One proposal offers two control operators: shift and reset. The reset operator sets the limit for the continuation while the shift operator captures or reifies the current continuation up to the innermost enclosing reset. For example, consider the following snippet in Scheme: The reset delimits the continuation that shift captures (named by k in this example). When this snippet is executed, the use of shift will bind k to the continuation (+ 1 represents the part of the computation that is to be filled with a value. This continuation directly corresponds to the code that surrounds the shift up to the reset. Because the body of shift (i.e., (k 5)) immediately invokes the continuation, this code is equivalent to the following: In general, these operators can encode more interesting behavior by, for example, returning the captured continuation k as a value or invoking k multiple times. The shift operator passes the captured continuation k to the code in its body, which can either invoke it, produce it as a result, or ignore it entirely. Whatever result that shift produces is provided to the innermost reset, discarding the continuation in between the reset and shift. However, if the continuation is invoked, then it effectively re-installs the continuation after returning to the reset. When the entire computation within reset is completed, the result is returned by the delimited continuation. For example, in this Scheme code: whenever CODE invokes (k N), (* 2 N) is evaluated and returned.

[ "Operator (computer programming)", "Continuation", "Semantics", "control" ]
Parent Topic
Child Topic
    No Parent Topic