Emulating GOTO in Scheme with continuations
Hacker News
February 19, 2026
AI-Generated Deep Dive Summary
The article explores how to emulate the controversial GOTO statement in Scheme using continuations, specifically through the `call/cc` procedure. While Dijkstra famously criticized GOTO for encouraging messy code, the piece argues that Scheme programmers shouldn’t be deprived of such control flow flexibility. By leveraging continuations, a powerful feature in Scheme, it’s possible to replicate the style and utility of GOTO within a more structured framework.
The article begins by explaining how GOTO works in other languages like BASIC and C. In BASIC, GOTO allows jumping between line numbers, creating loops or skipping sections of code. In C, GOTO is often used for error handling, enabling cleanups without repetitive code. However, these uses are not without criticism, as they can lead to less readable programs. The article then contrasts this with Scheme’s approach, where `call/cc` (call-with-current-continuation) provides a way to manage control flow by capturing the current continuation—the rest of the computation—and passing it to a procedure.
The author demonstrates how `call/cc` works through examples, showing that continuations can be used to create recursive-like behavior and alter program flow in ways similar to GOTO. By setting a variable to hold the continuation (`cont`), the article illustrates how Scheme can simulate jumps between code segments, effectively mimicking GOTO’s functionality while maintaining Scheme’s functional
Verticals
techstartups
Originally published on Hacker News on 2/19/2026