by hota_mazi · 3y ago · 0 comments
for (elems) |x| {
std.debug.print("{} ", .{x});
}
Why is the .{x} necessary here? What happens if I just write "x"?So, if you just type X, you're getting an error about it not being a struct. That's unless X is a struct with one field, where it'll just print that field. I find Zig meta-programming to actually be fairly readable, here's the function that does the formatting: https://github.com/ziglang/zig/blob/master/lib/std/fmt.zig
`.{a, b, c}` is the syntax for an anonymous struct/array/tuple, and a single element still needs to be wrapped in it.
[1] https://github.com/ziglang/zig/blob/f6c934677315665c140151b8...