3 ms·
That's not what "resume multiple times" is referring to here. You can typically only resume a coroutine once per yield, while a continuation generally allows yo
by Rusky 2y ago
That's not what "resume multiple times" is referring to here. You can typically only resume a coroutine once per yield, while a continuation generally allows you to return to the same place multiple times.
- naasking 2y agoRoughly, coroutine = a type of continuation with all mutable state, and continuation = a type of immutable coroutine.
- dkjaudyeqooe 2y agoOne 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 2y 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 2y ago[deleted]
- samatman 2y 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.