Re:Thoughts on Rust, a few thousand lines in
by hajile on Wednesday January 09, 2019 @04:17PM
(#18868981)
It is shadowing (though it could be converted into mutation by a sufficiently smart compiler...). ReasonML does something similar with their take on Ocaml.
Re:Thoughts on Rust, a few thousand lines in
by qznc on Wednesday January 09, 2019 @04:33PM
(#18869152)
The foos can all have different types which is not possible with mutation.
Re:Thoughts on Rust, a few thousand lines in
by int_19h on Wednesday January 09, 2019 @08:03PM
(#18870632)
Look at it closely - it's exactly the same as your OCaml example, except it uses ";" instead of "in", and indentation is adjusted accordingly.
Although in practice I found that it's common to not indent adjacent nested let..in blocks in OCaml, either, so you'd often see something like:
let foo = "..." in
let foo = parse(foo) in
let foo = escaped(foo) in
...
And the rules are really simple - "let" always introduces a new binding.
Re:Thoughts on Rust, a few thousand lines in
by UK-Al05 on Wednesday January 09, 2019 @04:15PM
(#18868968)
You can't mutate variables in rust without declaring mut
Re:Thoughts on Rust, a few thousand lines in
by StreamBright on Wednesday January 09, 2019 @04:19PM
(#18869006)
But how do you know just by reading that code? It would not be obvious to me at all.
Re:Thoughts on Rust, a few thousand lines in
by bryal on Wednesday January 09, 2019 @04:28PM
(#18869091)
I think it's quite fine to assume the reader knows enough rust to know the difference between mutable and immutable variables.
Re:Thoughts on Rust, a few thousand lines in
by empath75 on Wednesday January 09, 2019 @04:36PM
(#18869181)
let foo = bar;
let foo = bat;
is shadowing
let foo = bar; foo = bat;
is a compilation-time error because foo isn't mutable.
let mut foo = bar; foo = bat;
is reassignment.
in working code, either foo is declared as mutable or it's not, and it's pretty obvious from the code what's happening.
Re:Thoughts on Rust, a few thousand lines in
by StreamBright on Wednesday January 09, 2019 @05:12PM
(#18869507)
I guess. I would just never write code like that.
Re:Thoughts on Rust, a few thousand lines in
by goto11 on Wednesday January 09, 2019 @04:25PM
(#18869061)
You mean if you don't know the language?
Re:Thoughts on Rust, a few thousand lines in
by StreamBright on Wednesday January 09, 2019 @05:12PM
(#18869503)
I guess I just need to learn Rust. I wouldn't write a style of code where I have 3 lets after an other and using the same variable name.
Re:Thoughts on Rust, a few thousand lines in
by hamaluik on Wednesday January 09, 2019 @04:52PM
(#18869325)
I guess if you don't know rust you might not? But one of the first things you learn about rust is the `mut` keyword.
I would consider this shadowing (something you can do in OcaML):