4 ms·
> Passing parameters down the call stack is viral It's in a different league comparing to async-await abomination. For one, you can store parameter on a struct
by koiueo 1y ago
> Passing parameters down the call stack is viral
It's in a different league comparing to async-await abomination.
For one, you can store parameter on a struct thus working around the "virality" on a call site.
- 0x457 1y agoHuh? You have the following call stack (top to bottom): a -> b -> c -> d Function "d" does IO, so a, b and c need to pass that IO down. It's the same as with async in terms of virality. If I understood correctly, the main benefit here is that you don't have to dance around "can I call this function or is it going to block async runtime reactor?" I would pick async/await style over this because (I think) extra function argument is higher visual load than "async fn".
- koiueo 1y agoconst Greeter = struct { io: std.Io, pub fn greet(self: Greeter, msg: []const u8) !void { var stdout_writer = self.io.stdout.writer(); try stdout_writer.writeAll(msg); } } Greeter.greet("Look ma, no coloring")
- woodruffw 1y ago`greet` has Io within its closure, so I’m pretty sure this is consistent with the GP’s point.
- koiueo 1y agoIf you want to print a string from your function, you must supply it to the function. The fact that your function now receives `str: []u8` doesn't make it str-colored. On a side note: the entire "coloring" metaphor is extremely unfortunate and confusing IMO. It's somewhere at the top of my list (right beside the shroedinger's cat) of things which could've been explained better without dumbing them down.
- woodruffw 1y agoThat’s because str is not a meaningful effect, so we wouldn’t say that a function is “str-colored.” Function coloring is indeed confusing, which is why I’ve been trying to ground this on effects instead. Effects are IMO easier to understand, and this is a straightforward example of effect typing.
- 0x457 1y agoIf this is a special str that you have to pass down all the way through your call stack, then yes, it's str-colored.