3 ms·
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 Eleutheria 12y ago
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.
- bjz_ 12y agoWell then it would be: let var x = ... the `mut` or `var` is part of the pattern match.
- Eleutheria 12y agoNo. let x = 100 // constant var y = 200 // variable x = x + 1 // error y = y + 1 // 201
- sirclueless 12y ago'mut' conveys the same thing you are trying to convey with 'var' in a much better way. The term "variable" in programming languages doesn't carry any connotations of mutability or immutability. All it traditionally means is "named value" or "named memory address". 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.