When you call a function, you expect it to return — to hand control back to whoever called it. That feels natural because it mirrors how human conversation works: you ask, they answer, you continue. But this implicit "return to caller" is actually a hidden assumption baked into the language runtime. Continuation-passing style (CPS) makes that assumption visible by turning it into an ordinary function argument.
In CPS, no function ever returns. Instead, every function receives an extra argument called the continuation — a function that represents what to do next. When the function finishes its work, it calls the continuation with the result rather than returning. The continuation is the entire future of the computation, packaged into a callable value.
The idea was formalized in the 1970s, first appearing in Scheme and later explored deeply by Gerald Jay Sussman and Guy L. Steele Jr. in their work on the Lambda Papers (1975–1980). Their insight was that continuations are first-class: they can be stored, passed around, and invoked — which means every control-flow mechanism (returns, exceptions, early exits, coroutines, backtracking) can be expressed as a function call.
This is not a curiosity for language theorists. Modern async/await, generators, and even the halting problem all trace back to the same question: what exactly is "what happens next"?
Comments
Loading comments...