3 ms·
One lets you save and return to an execution state (program counter and local environment), the other lets you create and call an execution state that is saved
by dkjaudyeqooe 3y ago
One lets you save and return to an execution state (program counter and local environment), the other lets you create and call an execution state that is saved between calls to it.
There are obvious implementation differences but I'm not sure it makes any difference here, in both cases you can return to the same execution state multiple times.
- Rusky 3y agoThe difference is that resuming a coroutine mutates it, so that the next time you resume the same object it starts from wherever the coroutine next yielded. This may or may not be the same yield point as the last time, depending on the definition of the coroutine. A continuation is immutable in that way, so it is either an error to invoke it multiple times, or else it will always resume at the same place. Implementing coroutines in terms of continuations would mean capturing a new continuation each time you yield.
- deleted 3y ago[deleted]
- samatman 3y agoThe distinction between coroutines and delimited continuations is one-shot vs. multi-shot. The delimited continuation crowd use different language, but imagine an ordinary stackful asymmetric coroutine wrapped around a function call, except instead of just yield and resume, you have yield, resume, and reset. Call the coroutine, it yields from A, call resume, it yields from B, call reset, resume, it yields from B again. You can do that as often as you'd like. This can in fact be emulated with a coroutine generator and some fancy footwork, but it's a subtly different primitive.