DarwinBotsManual
Open the app EspañolES

swap

Swaps the top two numbers of the integer stack: a b swap leaves b a.

Facts

Word
swap
Aliases
swapint
Family
Basic
Integer stack
pops 2, pushes 2
What it does
Swaps the top two: a b becomes b a. With one number or none it does nothing.
Cost
Basic command
Runs
inside a gene: in the condition (cond) and in the body (start or else)

a b swap leaves b a. You can also write it as swapint. It's useful when the operands ended up in the opposite order from what the operator needs, which matters for the non-commutative ones: sub, div, mod, the comparisons or store.

WordStack afterwards
*.eye530 (for example)
4030 40
swap40 30
sub10

So, *.eye5 40 swap sub calculates 40 − *.eye5. This bot stores it in cell 50:

cond
start
  *.eye5 40 swap sub 50 store
stop

If the stack has a single number, or none, swap does nothing: it doesn't invent a zero the way over does. Its boolean stack counterpart is swapbool.