xor
Replaces the top two values of the boolean stack with one: true if exactly one of the two is.
Facts
xor, the exclusive or, pops the top two values of the boolean stack and pushes true if one is true and the other isn't. If both are the same (two trues or two falses), it gives false.
| Stack before (top on the right) | After xor |
|---|---|
| true false | true |
| false true | true |
| true true | false |
| false false | false |
It's useful for “one thing or the other, but not both”. The bot Acer Runco of Vita, The Weed of Life, from the Bestiary, uses it in a gene that turns and creates ties (here we show only the part that turns): among other conditions it requires either that it sees nothing straight ahead (.eyef) or that what it sees is of its own species (.refeye, .myeye), but not both at once:
' excerpt from Acer Runco of Vita: the conditions of one gene
cond
*40 11 =
*.robage 20 >
*.eyef 0 =
*.refeye *.myeye =
xor
start
40 *.aim add .setaim store
stopAnother way to see it: xor with a true inverts the other value, just like not, and with a false leaves it the same. And a b xor is true exactly when a and b are different.
With a single value on the stack, xor inverts it (the missing one counts as true); with an empty stack it pushes false. The bitwise exclusive or between numbers is ^.