4 ms·
Interesting. Integers are captured by reference in Go?
by jayd16 6y ago
Interesting. Integers are captured by reference in Go?
- shawnz 6y agoClosures capture all in-scope variables by reference in most languages. Same situation in Python for example: https://stackoverflow.com/questions/54288926/python-loops-and-closures https://stackoverflow.com/questions/54288926/python-loops-an...
- closeparen 6y agoYou can get bitten by a similar problem without closures if you stick a loop variable in an array. The loop variable is one address with contents mutating each iteration.
- masklinn 6y ago> You can get bitten by a similar problem without closures if you stick a loop variable in an array. Surely only if you store it indirectly, otherwise it'll be copied into the array.