But I think with functions it happens fairly regularly that they are part of an api that just requires mutability even when you don’t use it, that’s why I am not really for such a change, for me a function signature is part of library design and the types including const-ness should be picked by the author based on what makes sense for the api.
I guess otherwise you would be required to use _ = &arg;
to discard the error about it.
This doesn’t really make sense because zig doesn’t have mutable value parameters anyway.
fn notAllowed(arg: i32) void {
arg = 5;
}
pub fn main() !void {
notAllowed(5);
}
temp.zig:2:5: error: cannot assign to constant
arg = 5;
^~~
Language Reference - Pass by value Parameters
Primitive types such as Integers and Floats passed as parameters are copied, and then the copy is available in the function body. This is called “passing by value”. Copying a primitive type is essentially free and typically involves nothing more than setting a register.
Structs, unions, and arrays can sometimes be more efficiently passed as a reference, since a copy could be arbitrarily expensive depending on the size. When these types are passed as parameters, Zig may choose to copy and pass by value, or pass by reference, whichever way Zig decides will be faster. This is made possible, in part, by the fact that parameters are immutable.
I kind of like that function parameters are immutable, even if it just prevents people from doing weird code golf tricks of using them as local variables and mutating them a bunch.