Open tov opened 5 years ago
Question: Which of these is E1 += E2
sugar for?
E1.__iadd__(E2)
(fake syntax for references):
let rval = &E1
*E1 = *E1 + E2
Question: Which of these is
E1 += E2
sugar for?
E1.__iadd__(E2)
- (fake syntax for references):
let rval = &E1 *E1 = *E1 + E2
Personally, I think __iadd__
is the better choice. Suppose you have:
let a = [3, 4, None, None]
let b = [6, 8]
One could choose to implement:
let c = a + b
a == a # Not mutating
b == b # Not mutating
c == [3, 4, None, None, 6, 8]
a += b
a == [3, 4, 6, 8] # Mutating
Not the best design choice in my opinion, but someone might have a good reason for doing that.
We should be able to write: