3 ms·
But why would Go even allow you to mutate the temporary variable? For example, in Nim (it also prefers value semantics) this would result in a compile error:
by archargelod 3y ago
But why would Go even allow you to mutate the temporary variable?
For example, in Nim (it also prefers value semantics) this would result in a compile error:
var players = [1, 2, 3]
for player in players:
player = 0
Instead, you have to use the explicit `mitems` iterator, to get mutable references:
var players = [1, 2, 3]
for player in players.mitems:
player = 0
- Joker_vD 3y ago> why would Go even allow you to mutate the temporary variable? Because it's a variable. That's what you do with variables, you mutate them to hold different values. There are no "named, non-constant holders for values that you can't mutate directly" in Go.