Live data from Hacker News

What color is your function? (2015)

journal.stuffwithstuff.com

61–63 of 63 posts

Re: What color is your function? (2015)

#61

I wish there were a statically typed language with Lua's stackful coroutines and the ability to manually yield. It seems that Lua and Ruby are the only two well-known languages with that kind of stackful coroutine. And also, LuaJIT has proven that they can be implemented in a performant way, so I'm not sure if performance is a valid obstacle to implementing them more often. Even languages like Go and Java with proper…

I'm a huge fan of lua-like coroutines. Even though I have never written a line of lua I read all their papers on the topic.

Among the statically compiled languages, there are a few options in C++ for stackful coroutines, for example boost.context.

There is still a chance that they might make it into the standard at some point.

Re: What color is your function? (2015)

#62
post #57

Earlier quoted context omitted.

I believe it's up to the programmer to implement this. Here's some code from the zig github[1] page that illustrates how it might look once zig is stable (this is from an issue). pub fn write(file: *File, bytes: []const u8) usize { // Note that this is an if with comptime-known condition. if (std.event.loop.instance) |event_loop| { // non blocking version } else { // blocking call } } So I guess functions that don't…

Thanks, but how is a waiter suspended? The typical await implementation will do a CPS conversion of the waiter function, but to trigger the conversion it needs to see an await call, or pessimistically generate two versions of each functions. But from your example it seems that Zig just do context switching (not knocking it, I'm a big fan of it over await), but then why would it need an await/async keyword at all?

To answer myself. Zig doesn't really do separate compilation:

https://github.com/ziglang/zig/issues/233

Re: What color is your function? (2015)

#63
One thing I don't fully understand is how async-without-yield is different from the "bad" green threads as described in e.g. https://glyph.twistedmatrix.com/2014/02/unyielding.html

Are these two fundamentally opposing viewpoints? Or can these two sets of ideas be reconciled somehow?

The article that I posted specifically calls out Java as an example of why you need explicit await, yet the article in the OP praises Java for not having it!

Post reply on HN