

What is a continuation?
Aug 29, 2019
Dive into the intriguing world of continuations in programming! Discover how this concept shapes functional programming, especially in Scheme, while also influencing modern JavaScript techniques like async/await. Learn about continuation passing style (CPS) and how it transforms the way programs handle return values, all without relying on a stack. This exploration invites you to rethink function calls and exceptions, revealing the power of continuations in efficient coding.
AI Snips
Chapters
Transcript
Episode notes
Continuations and the Stack
- Functions typically use a stack to manage return pointers.
- Continuations reimagine this by turning the return pointer into a function argument, called 'K', which represents the rest of the computation.
Continuation-Passing Style
- If every function takes a continuation 'K', calls to 'K' become tail calls, eliminating the need for a return statement.
- This 'continuation-passing style' allows compilers to optimize function calls into simple jumps, removing the need for a stack.
JavaScript and Continuations
- JavaScript callbacks are essentially continuations, unknowingly used by many programmers.
- Asynchronous operations, like AJAX requests, demonstrate continuation-passing style through nested callback chains.