A "concatenative language"
Duplicates the top value on the stack
Drops the top value on the stack
Swaps the top two values on the stack
Drops the top value on the stack and tests it. If it is false, or 0, the program skips ahead past the matching 'then', otherwise the words in between are run. The 'then' itself is removed either way: it only marks the end of the branch, it never runs.
Or
Compares the top two values and leaves a flag in their place, true or false, which 'if' can take straight off the stack. They read in the order they are written, so '2 3 <' asks whether 2 is below 3.
Puts a flag on the stack, the same one a comparison leaves behind.
True only if both flags on top of the stack are true.
True if either of the two flags on top of the stack is true.
Turns the flag on top of the stack into its opposite.
Creates a new definition.
Example: ": double 2 * ;" defines a new word called double. Any subsequent mention of double will replace the word with its definition.
Unquotes the string on top of the stack: its words are put back in front of the program and run as if they had been written there.
: f>c 32 - 5 * 9 / ; 212 f>c
A word that calls itself is the only loop there is, and 'if' is what stops it.
: countdown dup if 1 - countdown then ; 5 countdown
: ! dup 1 > if dup 1 - ! * then ; 7 !
Every number in the sequence 0, 1, 1, 2, 3, 5, 8 is the sum of the two before it, so 'fib' calls itself twice: once for each of them, with 'swap' digging the original number back out from under the first result.
: fib dup 1 > if dup 1 - fib swap 2 - fib + then ; 6 fib
A string is data sitting on the stack until ',,' puts it back into the program, where it is code again.
: double " 2 * " ,, ; : quadruple double double ; 5 quadruple