Various languages support (some flavor of) coroutines.
One way to discriminate coroutines is whether they are stackful or not (terminology based on Ana Lucia de Moura; Roberto Ierusalimschy (2004). “Revisiting Coroutines”. doi:10.1145/1462166.1462167. CiteSeerX: 10.1.1.58.4017.):
-
stackful coroutines allow that a
yield
orsuspend
of a coroutine can be done from a function that is being called by a coroutine, i.e., from nested invocations and this implies that the whole call stack has to be preserved when the coroutine is suspended. -
non stackful coroutines impose the restriction that the
yield
orsuspend
can only be done in the body of the coroutine itself.
Clearly, stackful coroutines have advantages in terms of modularization but are more expensive to implement. My question is therefore: which languages have the best support for stackful coroutines?
Although I have looked at various languages (including Python, Ruby, Javascript, Lua, Scheme) the terminology in all these languages is so different and the descriptions are often so unclear that I prefer expert advice.
P.S. I am aware of the fact that coroutines can be implemented using continuations, but the question is specifically about languages that natively support coroutines.
14