Hacker News new | ask | show | jobs
by silentbicycle 5731 days ago
It's probably helpful to think of coroutines as first-class functions with independent call stacks, which can be suspended and resumed (potentially returning and passing in new arguments). Coroutines are also usable as (one-shot) continuations, and continuations can be used to implement coroutines.

There's a great paper about coroutines ("Revisiting Coroutines", http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.58.4...) co-written by one of the primary Lua authors.

FWIW, you can also stream Lua functions (with string.dump), though it takes a bit of extra trouble to stream functions with nonlocal values ("upvalues"/closures). I don't know if it's possible to stream Lua coroutines, though. As with most things, Erlang's immutability makes streaming them much easier.