Re:Go: Redefining For Loop Variable Semantics
by kevincox on Tuesday October 11, 2022 @03:00PM
(#33167631)
Not quite how you tested it. The `move` is actually copying the variable:
But the most equivalent code would be the following which doesn't compile:
[ Parent
| on HN ]
Re:Go: Redefining For Loop Variable Semantics
by littlestymaar on Tuesday October 11, 2022 @04:55PM
(#33169128)
That's the point: the misleading code doesn't compile because the `i` variable scope in limited to the current execution of the loop (and that's why you can't borrow it for `functions`'s lifetime), which is exactly how ES6 fixed this in JavaScript.