let (x, var y) = ... can easily express the intention.
Also, communication is in the ear of the beholder. Var: variable, that varies. 'Let' would be immutable by default.
Thanks for the response anyway.
Also, communication is in the ear of the beholder. Var: variable, that varies. 'Let' would be immutable by default.
Thanks for the response anyway.
It's actually entirely reasonable to have an "immutable variable" -- Rust uses this phrase in its error messages and it's perfectly sensible. For example, consider this snippet:
pub fn is_even(x: int) -> bool {
let y = (x / 2) * 2 - x;
if (y == 0) {
return true;
} else {
return false;
}
}
Not very idiomatic, forgive me, but would you say that y "varies"? I would say yes, it varies for each invocation of is_even(). If y didn't vary, "if (y == 0)" would be a nonsense statement. y is certainly immutable -- you can't go assigning new values to it -- but it's definitely a variable.The opposite of "variable" is "a constant," not immutable. 'mut' means "mutable" and "mutable vs. immutable" is the choice here. Rust got this right, I think.
let var x = ...
the `mut` or `var` is part of the pattern match. let x = 100 // constant
var y = 200 // variable
x = x + 1 // error
y = y + 1 // 201