The Eric Normand Podcast

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.
Ask episode
AI Snips
Chapters
Transcript
Episode notes
INSIGHT

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.
INSIGHT

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.
ANECDOTE

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.
Get the Snipd Podcast app to discover more snips from this episode
Get the app