Why does assignment return the previous value instead of the new value, re example: assigns 0
to y
instead of 2
? This is dangerously unusual as it violates the principle of least surprise.
var x: I32 = 0
let y = (x = 2)
Why does assignment return the previous value instead of the new value, re example: assigns 0
to y
instead of 2
? This is dangerously unusual as it violates the principle of least surprise.
var x: I32 = 0
let y = (x = 2)
I am pretty sure this was done to get consistent results for
iso
variables. Assignment to aniso
variable would not be able to return the new value because that created an alias. But it's true that a less surprising design would involve an assignment operator returningNone
and some other operation (swap?) for the recovery of the original value that is being overwritten.