by anon-3988 · 1y ago · 0 comments
a = 10; { a = 20; } print(a)
This would print 10. Something like that. I just remembered that the first time I encountered this, I thought "this is going to be one of those things where I will unnecessarily trip over" and closed the page.
let a = 10;
{
let a = 20;
}
print(a);
And even more clear in OCaml: let a = 10 in
begin
let a = 20 in
()
end;
print a
BTW you should also close the page on Rust then, which also has OCaml-like variable shadowing (and many other languages use very similar forms of shadowing, such as local variables shadowing object fields in Java/C#).