@page "/Concat" Concatenator

A "concatenative language"

Or

Example: ": double 2 * ;" defines a new word called double. Any subsequent mention of double will replace the word with its definition.

Fahrenheit to Celsius Replace program
                : f>c   32 - 5 * 9 / ;
                212 f>c
            
Countdown Replace program

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
            
Factorial Replace program
                : !   dup 1 > if dup 1 - ! * then ;
                7 !
            
Fibonacci Replace program

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
            
Quoting Replace program

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