DarwinBotsManual
Open the app EspañolES

++

Adds 1 to the number on top of the integer stack, without touching memory: 5 ++ leaves 6.

Facts

Word
++
Family
Bitwise
Integer stack
pops 1, pushes 1
What it does
Replaces the top with that number plus 1. At the edge of 32 bits, 2147483647 ++ gives 0.
Cost
Bitwise command
Runs
inside a gene: in the condition (cond) and in the body (start or else)

x ++ pops a number and pushes that number plus 1. 5 ++ gives 6, -1 ++ gives 0. For the numbers you will be handling it is the same as 1 add, written shorter.

The bot Guardian-0.9 (Trafalgar), from the Bestiary, uses it in a trick to turn any number into an “is zero” flag: x sgn abs - ++ leaves 1 if x is 0 and 0 if not. Step by step, with x = −9 and with x = 0:

WordStack (x = −9)Stack (x = 0)
sgn−10
abs10
-−10
++01

Multiplied by a value, it lets you write something only when a cell is at 0, without using conditions. This gene stores 700 in cell 80 only if it was empty:

cond
start
  700 *80 sgn abs - ++ mult *80 add 80 store
stop

If cell 80 held 0, the flag is 1 and 0 + 700 is stored; if it already held something, the flag is 0 and what was there is stored again.

One inherited quirk, only at the edge of 32 bits: ++ on the largest number that fits on the stack (2147483647) gives 0 instead of wrapping around to the most negative number (−2147483648). With an empty stack it operates on 0 and leaves 1. Its opposite is --.