DarwinBotsManual
Open the app EspañolES

xor

Replaces the top two values of the boolean stack with one: true if exactly one of the two is.

Facts

Word
xor
Family
Logic
Boolean stack
pops 2, pushes 1
What it does
Pops two values from the boolean stack and pushes true if exactly one of them is true. With only one it inverts it; with an empty stack it pushes false.
Cost
Logic
Runs
inside a gene: in the condition (cond) and in the body (start or else)

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 falsetrue
false truetrue
true truefalse
false falsefalse

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
stop

Another 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 ^.