News for hackers. Stuff that matters.

tmazeika

Re:Go: Redefining For Loop Variable Semantics on Tuesday October 11, 2022 @10:33AM (#33163834)
The example makes sense when you think of `i` getting reassigned, but in other languages with variable shadowing (think Rust, but Go too when you're in a nested scope) you might replace `i = 2` with `let i = 2` (Rust), in which case the closure closes over precisely the `let i = 2` variable and the expected output differs.