Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This classification seems somewhat Rust-centrict. The terminology I'm more used to seeing for coroutines is this:

Symmetric vs assymetric coroutines: symmetric coroutines are the original style, where the currently executing coroutine decides who to transfer control to. Assymetric coroutines have a caller and a callee and the callee always yields control back to the caller. (This is much more common today)

Stackful vs stackless coroutines: in a stackless setting the language distinguishes between synchronous and asynchronous functions. This is what Python and Rust generators do. In a stackless setting (such as Lua), every function can potentially yield or call a sub-function that yields.

Exception handling is somewhat similar to stackless coroutines, specially in languages such as Common Lisp where the exception handler can choose to resume execution from the point that raised the exception, instead of unwinding the stack.



> symmetric coroutines are the original style

This isn't quite correct, but it's close. The original style were co-routines, as distinguished from subroutines, this was when programming was still heavily goto-oriented, these were little more than patterns used to structure go-to.

Simula, if I recall correctly, was the first high-level language to have coroutines, and they were basically asymmetric. I say basically because there was a mechanism for a coroutine to replace itself with another coroutine, but it wasn't a general transfer mechanism. Not unlike a delimited continuation in fact.

Good summary of how it all works however! I believe this is a typo:

> In a stackless setting (such as Lua)

Since Lua is stackful, and you're contrasting it with stackless generators.


yup, was a typo >_<


I don't see how exception handling is similar to stackless coroutine as it is very non local.


Sorry, I meant stackful (was a typo)


Ah, yes, then I agree completely!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: