3 ms·
Continuations can be used to implement higher-level constructs like exceptions, generators, async calls and so on. For a language like Scheme which prefers a fe
by olavk 8y ago
Continuations can be used to implement higher-level constructs like exceptions, generators, async calls and so on. For a language like Scheme which prefers a few powerful primitives, it gives the user the power to implement such constructs on their own. Most mainstream languages prefer to keep such powerful tools out of the hands of users, and instead provide higher-level constructs like exceptions, generators, async etc. as part of the core language. It is a trade-off between power and consistency (like macros) - the trade-off which is the stuff of language flame-wars.
There is nothing "mathy" about continuations to my understanding. They are like GOTO, a low-level construct which can be used to implement higher-level constructs which are more appropriate in regular applications. Basically, continuation captures the program counter (the address of the current instruction) and the current environment and stack. This allows you to "save" (like in a computer game) the current execution state, and then restore it as needed.