News for hackers. Stuff that matters.
Re:Zig in 30 Minutes by hota_mazi on Sunday January 03, 2021 @01:46AM (#25620064)
> std.debug.print("foo param: {}\n", .{x});

Why is this ".{x}" and not just "x"?

This syntax is used tens of times in the following code snippets but never explained.

Re:Zig in 30 Minutes by dnautics on Sunday January 03, 2021 @01:51AM (#25620081)
Thanks for the catch! It's an anonymous array. Later down there is a place where there are two sets of brackets in the print string, and the so the anonymous array passed to it has to have two items (the string is analyzed and the correct size of the array is compile-time checked, no stack drilling here).
Re:Zig in 30 Minutes by hota_mazi on Sunday January 03, 2021 @01:55AM (#25620102)
Does this mean that "print" only takes two arguments, and the second argument has to be an array?

This is the kind of information that your tutorial needs to contain, because it's radically different from C and other languages, and this is exactly the kind of information that readers will be looking for: "How different is Zig from C and why should I care?".

Re:Zig in 30 Minutes by dnautics on Sunday January 03, 2021 @01:58AM (#25620109)
Yep! The document has now been updated. I might have been blind to it because my daily driver is Elixir, and it does "basically the same thing" with keyword arguments.
Re:Zig in 30 Minutes by hota_mazi on Sunday January 03, 2021 @02:13AM (#25620172)
I totally understand why being immersed in something might make you lose perspective, but keeping this perspective is what differentiates a decent language designer from a great one.

Does this mean that zig doesn't support varargs? If not, why not?

Again, another question that a lot of people coming to your page will be asking themselves, please don't take that as a criticism, just candid feedback to help you make your article better.

Re:Zig in 30 Minutes by edflsafoiewq on Sunday January 03, 2021 @03:00AM (#25620364)
Zig does not have varargs. They were removed in favor of anonymous structs/tuples. See https://github.com/ziglang/zig/issues/208#issuecomment-39377....
Re:Zig in 30 Minutes by dnautics on Sunday January 03, 2021 @02:18AM (#25620183)
I'm not the creator of zig! Thank you for your advice.

Zig does not support varargs, except when calling C functions.

Re:Zig in 30 Minutes by aidenn0 on Sunday January 03, 2021 @03:06AM (#25620388)
Isn't it an anonymous struct, not an anonymous array? (IIRC it can't be an array, since it must support heterogenous types)
Re:Zig in 30 Minutes by dnautics on Sunday January 03, 2021 @03:50AM (#25620547)
You're right! It's an anonymous struct with numbered fields. I forgot about that.
Re:Zig in 30 Minutes by zamadatix on Sunday January 03, 2021 @01:51AM (#25620083)
To allow for multiple substitutions to be done the same way.
Re:Zig in 30 Minutes by hota_mazi on Sunday January 03, 2021 @01:53AM (#25620093)
Sorry but that doesn't explain anything.

Why is just "x" not allowed? What does ".{x}" actually mean?

Re:Zig in 30 Minutes by flohofwoe on Sunday January 03, 2021 @05:35AM (#25620956)
.{ x } or .{ x, y, z } etc... are adhoc-constructed anonymous struct-values which can be inspected at compile time by the standard library's string formatting code.

It all makes a lot more sense after understanding Zig's comptime features:

https://ziglang.org/documentation/master/#comptime

The end of the comptime section also explains how string formatting works that way.