Similar to +=, -=, *=, or /= being able to do something like x or= 0b110101 would be really nice syntactic sugar. The alternative someLongerName = someLongerName or (extremelyComplex and geniusBitFiddling) becomes quickly hard to read (and write).
I noticed that simply creating a new operator function (func `or=`(a: var SomeNumber, b: SomeNumber) =) doesn't to work, as when using this function, the keyword or messes things up (?).
Is it possible within reasonable expenses to implement something that this could work? Of course, one could use something like |= or &= but this is probably even more confusing.
Wouldn't mask_with be more meaningful than and=? similarly with the others?
(I might be misremembering which is used for what.)
func `or=`(a: var SomeNumber, b: SomeNumber) = declares a new setter property which needs to be used yourInt.or = otherInt. It does not make a new infix operator or=. Aside from that I dont think a word operator + symbol operator looks all that nice or is that intuitive.
I think it's just nicer to have a func bitOr(a: var SomeNumber, b: SomeNumber)`(Perhaps `bitOrAssign) which is obviously best used as yourInt.bitOr otherInt.
A bit of a digression but nonetheless there is a trap with Nim's bitwise ops ...
I have not forgotten about this trap and would really like to change this for version 2.0 but I fear the outrage. :-)
Bigints already has that, and it is needed because the big int may be too big to copy
https://nim-lang.github.io/Nim/jsbigints.html#%2F%3D%2CJsBigInt%2CJsBigInt
import std / bitops
var v = 0b0000_0011'u8
v.setBits(3, 5, 7)
doAssert v == 0b1010_1011'u8