status: final (2023-04-25)
keywords: Continuations, Control FlowSee also SRFI 18: Multithreading support, SRFI 34: Exception Handling for Programs, SRFI 39: Parameter objects, SRFI 45: Primitives for Expressing Iterative Lazy Algorithms, SRFI 97: SRFI Libraries, SRFI 154: First-class dynamic extents, SRFI 155: Promises, SRFI 157: Continuation marks, and SRFI 158: Generators and Accumulators.
Whenever an expression is evaluated during the run of a Scheme program, there is a continuation awaiting the values of the expression. It is a distinguishing property of the Scheme programming language to offer a procedure (named
call/cc) that captures the current continuation as a procedure, which, when called, aborts the then-current continuation and reinstates the captured one.
One can visualize a continuation as a list of (continuation) frames where a non-tail call adds a frame to the top of the list and where the return from a non-tail call removes the appropriate frame.
Moreover, each expression is evaluated in a dynamic environment that conceptually holds the values of parameters like the current output port and the dynamic-wind stack at the point of evaluation. As the dynamic environment is captured and reinstated along the continuation when the
call/cc machinery is used, we can view it conceptually as part of the continuation.
The libraries defined in this SRFI are all concerned with continuations in a wider sense. More specifically, the topics are as follows:
call-with-current-continuation. Moreover, a procedure to capture so-called composable continuations is provided. As opposed to continuations captured by
call-with-current-continuation, invoking a composable continuation does not abort the then-current continuation, so composable continuations behave like ordinary procedures. Together with continuation prompts, composable continuations allow one to implement the various proposed sets of control operators for delimited continuations. Finally, a primitive (
call-in-continuation) is provided that allows calling a procedure in a given continuation instead of just delivering values to it.
with-exception-handlerprocedure and the
guardsyntax gain additional tail-context guarantees.
parameterizesyntax gains an additional tail-context guarantee. To support an alternative model of parameters that is linked to the dynamic extent and not to the current parameterization, the notion of a parameter-like object and the
temporarilysyntax are introduced.
Large parts of this SRFI have been inspired by the control operators provided by Racket.