Re:I Want Off Mr. Golang's Wild Ride
by hope-striker on Friday February 28, 2020 @03:26PM
(#22446003)
You seem to be confusing mutable variables with mutable references. A name, in Python, is a mutable cell that holds a reference. Python names definitely correspond to mutable, not immutable variables in Rust.
[ Parent
| on HN ]
Re:I Want Off Mr. Golang's Wild Ride
by joshuamorton on Friday February 28, 2020 @03:29PM
(#22446035)
Well no, for the reason I describe above: if you have the pattern
mut a = 4
f(a)
print(a)
In rust and python, you'll always get 4 in python, but the value in rust depends on `f`.This means that the passed variable is immutable but shadowable, as in rust. (An object in python is much more like an Box/Cell, so the contained object can be mutated, but the reference to the box itself is immutable).
Re:I Want Off Mr. Golang's Wild Ride
by hope-striker on Friday February 28, 2020 @03:32PM
(#22446064)
The value in Rust does not depend on f.
I will be precise. There is no definition of f such that this function will print anything other than "4".
fn main() {
let mut x = 4;
f(x);
println!("{}", x);
}
Again, you seem to be confusing mutable references and mutable variables. If I had written f(&mut x) rather than f(x), you would be right.