Gerald Jay Sussman and Guy L. Steele, Jr. coined the phrase in AI Memo 349 (1975), which sets out the first version of the Scheme programming language.
Expressing code in this form makes a number of things explicit which are implicit in direct style.
[5] Functional compilers can also use A-normal form (ANF) (but only for languages requiring eager evaluation), rather than with 'thunks' (described in the examples below) in CPS.
This, along with a restrictive style prohibiting a variety of constructs usually available, is used to expose the semantics of programs, making them easier to analyze.
In the example above (assuming that CPS primitives have been provided), we might call (factorial& 10 (lambda (x) (display x) (newline))).
For example, let's break the execution of the pyth function if at least one of its arguments is negative returning zero: Programming with continuations can also be useful when a caller does not want to wait until the callee completes.
This call returns right away, allowing the application code to continue while the user interacts with the dialog box.
Writing in trampolined style, however, is extremely difficult; when used, it is usually the target of some sort of transformation, such as compilation.
Functions using more than one continuation can be defined to capture various control flow paradigms, for example (in Scheme): It is of note that CPS transform is conceptually a Yoneda embedding.
For example, within linguistic semantics, Chris Barker and his collaborators have suggested that specifying the denotations of sentences using CPS might explain certain phenomena in natural language.
Unlike the regular double-negation translation, which maps atomic propositions p to ((p → ⊥) → ⊥), the continuation passing style replaces ⊥ by the type of the final expression.
Accordingly, the result is obtained by passing the identity function as a continuation to the CPS expression, as in the above example.