Currently, e.g. += is defined as
template `+=`*(a: var BigInt, b: BigInt) =
a = a + b
This causes a to be evaluated twice, which can produce unexpected results, when it's an expression that can cause side effects. For example
proc lol(x: var BigInt): var BigInt =
echo "hello ", x
x
var a = 42.initBigInt
lol(a) += 1.initBigInt
prints hello 42 twice, instead of just once.
The solution would be to just make it a func instead. The same applies to -= and *=.
Currently, e.g.
+=is defined asThis causes
ato be evaluated twice, which can produce unexpected results, when it's an expression that can cause side effects. For exampleprints
hello 42twice, instead of just once.The solution would be to just make it a
funcinstead. The same applies to-=and*=.