4 ms·
Well, almost. A coroutine is created once and it yields control to its "caller" each time it produces an item. To implement a coroutine, you only need to save
by zvrba 13y ago
Well, almost.
A coroutine is created once and it yields control to its "caller" each time it produces an item. To implement a coroutine, you only need to save its stack (local variables, instruction pointer).
He created a lazy stream: instead of yielding control for each item produced, it makes a linked list of items where each node is created on demand.
Thus, coroutines only return the "next" item, while streams compute and store the history of the whole computation.
- adamnemecek 13y agoNot to nitpick but you are talking about generators which IIRC are also incorrectly called coroutines in the Python community. A proper coroutines are not limited to yielding control to the caller, but anywhere.
- zvrba 13y agoI've described what's usually known as asymmetric coroutines or semicoroutines. "Asymmetric" because [as claimed by Lua manual at least] there are two separate calls for control transfer (yield and resume). Generators are less powerful. See http://www.lua.org/pil/9.1.html http://www.lua.org/pil/9.1.html