News for hackers. Stuff that matters.
Re:A Review of the Zig Programming Language (Using Advent of... by chubot on Monday December 27, 2021 @12:17PM (#29704383)
I thought this syntax was weird too, but one cool thing is that you can ask for the index too

    for (items) |i, item| {
    }
I guess Go does something similar, but it's a little weirder IMO because it has maps, while Zig doesn't.

I suppose it could have been

    for i, item in items {
    }
But I guess coming from Python that feels like tuple unpacking, which I don't think Zig has, but could make sense?
Re:A Review of the Zig Programming Language (Using Advent of... by ReactiveJelly on Monday December 27, 2021 @06:50PM (#29708402)
Lua also has

    for i, v in ipairs (t) do
        -- i is the index, v is the value
    end
Not getting the index in C++ easily was very frustrating. Often in C++ I fall back on C-style for-loops just because the functional stuff is hard to remember.

In Rust it doesn't give you the index by default, but the `enumerate` adapter adds an index anywhere in a functional pipeline.