Forth Language Summary top + 3 5 + 8 - 9 2 - 7 * 4 5 * 20 / 20 4 / 5 MOD 11 3 MOD 2 /MOD 11 3 /MOD 3 2 remainder, then quotient HEX (sets the mode) DECIMAL BASE 7 BASE ! (BASE is special variable) DUP 3 DUP 3 3 duplicates top SWAP 1 2 3 4 SWAP 3 4 2 1 swaps top two DROP 1 2 3 4 DROP 3 2 1 pops top OVER 1 2 3 4 OVER 3 4 3 2 1 DUPs the second from top ROT 1 2 3 4 ROT 2 4 3 1 rotates 3rd up to top ?DUP 1 2 3 0 ?DUP 4 3 2 1 DUP only if top is not 0 DEPTH 3 3 3 3 DEPTH 3 3 3 3 4 depth of stack ABS -4 ABS 4 MAX 3 6 MAX 6 MIN 3 6 MIN 3 MINUS 13 MINUS -13 CONSTANT 6 CONSTANT SIX SIX can be used for 6 VARIABLE VARIABLE X X is declared a variable ! 25 X ! X = 25 +! 4 X +! X = X + 4 @ X @ 29 retrieves value of X : ; : SQR DUP * ; defines procedure SQR . 1 2 3 4 . 3 2 1 pops and PRINTS top to screen .R 13 5 .R PRINTS the 13 right justified 5 columns CR carriage return ." ." Howdy" PRINTS Howdy to screen < 3 5 < 1 1: true 0: false > 3 5 > 0 = 3 5 = 0 0< -4 0< 1 negative 0> -4 0> 0 0= -4 0= 0 AND 13 11 AND 9 1101 AND 1011 = 1001 OR 13 11 OR 15 1101 OR 1011 = 1111 XOR 13 11 XOR 6 1101 XOR 1011 = 110 NOT -2 NOT 1 ...1110 NOT --> ...0001 DO LOOP 5 2 DO ." hi" LOOP hi hi hi (5 is limit, 2 is start) +LOOP 5 2 DO ." hi" 2 +LOOP hi hi (count by 2) I 5 2 DO I . LOOP 2 3 4 (retrieve counter to stack) IF 3 5 < IF ." hi" THEN hi (if 3 < 5 then print hi) IF ELSE 3 5 < IF ." hi" ELSE ." no" THEN hi (if 3 < 5 then hi else no) WHILE 1 BEGIN DUP 20 < WHILE . 2 + REPEAT BEGIN test WHILE loop-stuff REPEAT UNTIL BEGIN loop-stuff test UNTIL