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.
| Word | Stack afterwards |
|---|---|
*.eye5 | 30 (for example) |
40 | 30 40 |
swap | 40 30 |
sub | 10 |
So, *.eye5 40 swap sub calculates 40 − *.eye5. This bot stores it in cell 50:
cond
start
*.eye5 40 swap sub 50 store
stopIf 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.