News for hackers. Stuff that matters.
Re:John Carmack on Mutable Variables by ghurtado on Friday October 31, 2025 @11:52AM (#45773473)
That's the opposite of what any reasonable engineer means by "constant".
Re:John Carmack on Mutable Variables by fnordsensei on Friday October 31, 2025 @12:44PM (#45774034)
That’s the point, you’re just haggling about scopes now. All the way from being new per program invocation to new per loop.

Immutability doesn’t have this connotation.

Re:John Carmack on Mutable Variables by davrosthedalek on Friday October 31, 2025 @01:04PM (#45774245)
How? I think the same argument applies: If it's changing from loop to loop, seems mutable to me.
Re:John Carmack on Mutable Variables by Zambyte on Friday October 31, 2025 @03:59PM (#45776074)
I can give a specific example.

    for (0..5) |i| {
        i = i + 1;
        std.debug.print("foo {}\n", .{i});
    }
In this loop in Zig, the reassignment to i fails, because i is a constant. However, i is a new constant bound to a different value each iteration.

To potentially make it clearer that this is not mutation of a constant between iterations, technically &i could change between iterations, and the program would still be correct. This is not true with a c-style for loop using explicit mutation.

Re:John Carmack on Mutable Variables by skeezyjefferson on Thursday November 06, 2025 @09:47AM (#45835834)
I argue in your example there are 6 constants, not 1 constant with 6 different values, though this could be semantics ie we could both be right in some way
Re:John Carmack on Mutable Variables by Zambyte on Monday November 10, 2025 @01:16PM (#45878912)
Exactly. As said higher in this comment chain:

> So, constant, but repeatedly redefined.

Re:John Carmack on Mutable Variables by skeezyjefferson on Tuesday November 11, 2025 @06:28AM (#45886173)
it was constant if it could have been redefined, by the basic definition of what constant means. so no, not constant, but constants
Re:John Carmack on Mutable Variables by fnordsensei on Friday October 31, 2025 @01:14PM (#45774345)
I think you’re after something other than immutability then.

You’re allowed to rebind a var defined within a loop, it doesn’t mean that you can’t hang on to the old value if you need to.

With mutability, you actively can’t hang on to the old value, it’ll change under your feet.

Maybe it makes more sense if you think about it like tail recursion: you call a function and do some calculations, and then you call the same function again, but with new args.

This is allowed, and not the same as hammering a variable in place.

Re:John Carmack on Mutable Variables by davrosthedalek on Friday October 31, 2025 @01:03PM (#45774230)
No? It has a lifetime of one loop duration, and is constant during that duration. Seems perfectly fine to me.