Emulating Goto in Scheme with Continuations
2 days ago
- #call/cc
- #Scheme
- #GOTO
- Dijkstra criticized the GOTO statement for being too primitive and messy.
- Scheme lacks GOTO but can emulate it using call/cc (call-with-current-continuation).
- GOTO allows jumping to different parts of the code, useful for loops and cleanup.
- call/cc captures the current continuation, enabling control flow manipulation.
- A macro 'with-goto' is implemented in Scheme to simulate GOTO using call/cc.
- Labels in 'with-goto' are defined as thunks (procedures with no arguments).
- Continuations allow jumping to labels without returning to the original call site.
- The implementation is inefficient and not practical but demonstrates call/cc's power.
- Delimited continuations are suggested as a better alternative to call/cc.