Making the remainder explicit

A direct-style addOne(x) returns x + 1. In CPS, addOne(x, k) gives x + 1 to k, which represents what should happen with the result.

For 2 × addOne(3), that continuation can multiply the received result by two. Context formerly implicit in the return path becomes something the program names and passes.

References: [1] [2]

A transformation of control structure

A CPS transformation rewrites relevant calls to accept continuations and makes the required evaluation order explicit. The continuation carries unfinished work; primitive arithmetic may remain direct under the chosen representation.

This helps explain callbacks awaiting a web response and also supplies a compiler representation. Changing control structure does not itself enlarge the language’s set of computable problems.

References: [1] [2]

Tail calls still carry state

In a fully transformed model, control transfers can be tail calls, but unfinished work still lives in continuations. Closures may retain variables needed later; tail-call form does not imply zero allocation or zero saved state.

Shao and Appel relate continuation contexts to caller-save and callee-save registers. Performance depends on representation and compilation, and CPS alone neither guarantees speed nor starts another thread.

References: [3]