Is there a shortcut for x = x or y similar to the shortcut for x = x + y ?
This would be useful in the situation where x is a complex access expression such as used in:
table[indexProc(w)] = table[indexProc(w)] or y
especially where indexProc might have side effects that were NOT WANTED to be executed twice.
It did not appear in the manual that or= was a legal token.
Nim doesn't have such an operator in system but it's easy enough to write your own:
template `|=`(a, b): untyped =
var x = addr(a)
x[] = x[] or b
table[indexProc(w)] |= y
I don't find that easy. Looks like voodoo at first :)
So taking the addr() does evaluate the expression once and using the address of the result with de-referencing lets you assign to it. Is that how it works?
Looks like voodoo at first
It's the same as
auto p = &table[indexProc(w)];
*p = *p | y;
in C++ ... although in modern idiomatic C++, it would be
auto& p = table[indexProc(w)];
p = p | y;