sd:star_forth_dictionary
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| sd:star_forth_dictionary [2026/04/14 06:09] – created appledog | sd:star_forth_dictionary [2026/04/26 08:57] (current) – appledog | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | = Star Forth Dictionary | ||
| + | Also see: [[Star Forth Test Suite]] | ||
| + | Here is a list of each word that comes standard in Star Forth. Included is a short definition as to its general usage. | ||
| + | |||
| + | == + (add) | ||
| + | This adds the two numbers on the top of the stack and pushes the result. | ||
| + | |||
| + | 1 2 + . | ||
| + | |||
| + | This puts a 1 and a 2 on the stack, then adds them and pushes the result. Then, the . (dot) command prints the result, which is 3: | ||
| + | |||
| + | 3 ok | ||
| + | |||
| + | == BYE | ||
| + | This quits the REPL (the Forth environment). | ||
| + | |||
| + | Usage: | ||
| + | |||
| + | BYE | ||
| + | |||
| + | == . (dot) | ||
| + | This is the " | ||
| + | |||
| + | 5 . ( this prints 5. ) | ||
| + | 1 1 + . ( this prints 2. ) | ||
| + | |||
| + | == DOW | ||
| + | DOW ( -- n ) Day of week 0=Sun 6=Sat | ||
| + | |||
| + | Pushes day of week to stack. | ||
| + | |||
| + | == DUP | ||
| + | This command duplicates the top item on the stack. So if your stack is: | ||
| + | |||
| + | 1 2 3 | ||
| + | |||
| + | then '' | ||
| + | |||
| + | 1 2 3 3 | ||
| + | |||
| + | == 2DUP | ||
| + | : 2DUP OVER OVER ; | ||
| + | |||
| + | This duplicates the top 2 items on the stack. If the stack holds '' | ||
| + | |||
| + | == DROP | ||
| + | Drops the TOS. If the stack is '' | ||
| + | |||
| + | == 2DROP | ||
| + | : 2DROP DROP DROP ; | ||
| + | |||
| + | This command drops twice. If the stack is '' | ||
| + | |||
| + | == EVALUATE | ||
| + | Like EVALUATE from ANS Forth. | ||
| + | |||
| + | Experimental command. | ||
| + | |||
| + | Also see: INCLUDE | ||
| + | |||
| + | == FORGET | ||
| + | If you forget a word, then it (and any word defined after it) is unlinked from the dictionary. So if you define three words and FORGET the second one, the third one is also forgotten. | ||
| + | |||
| + | == INCLUDE | ||
| + | INCLUDE command. Experimental. | ||
| + | |||
| + | Also see: EVALUATE | ||
| + | |||
| + | == LEAVE | ||
| + | LEAVE ( -- ) Exit DO loop immediately | ||
| + | |||
| + | == LROT | ||
| + | Bitwise left rotate. | ||
| + | |||
| + | Also see: RROT, LSHIFT, RSHIFT | ||
| + | |||
| + | == LSHIFT | ||
| + | Bitwise shift left. | ||
| + | |||
| + | Also see: LROT, RROT, RSHIFT | ||
| + | |||
| + | == MAX | ||
| + | : MAX 2DUP < IF SWAP THEN DROP ; | ||
| + | |||
| + | A nice command. It does 2DUP then picks the highest number. How it works is easy; if the TOS is greater than the 2nd one down, it swaps them and drops the low one. Otherwise it drops TOS (because it's smaller). Note that the IF consumes the original numbers, so the only number left is the MAX one. | ||
| + | |||
| + | stack: | ||
| + | step1: | ||
| + | step2: | ||
| + | step3: | ||
| + | step4: | ||
| + | |||
| + | == MIN | ||
| + | : MIN 2DUP > IF SWAP THEN DROP ; | ||
| + | |||
| + | MIN is the opposite of MAX. The difference is that the comparator ('>' | ||
| + | |||
| + | == MS | ||
| + | MS ( -- n ) Milliseconds 0-999 | ||
| + | |||
| + | Timer function. | ||
| + | |||
| + | == .N (dotn) | ||
| + | This is the print command, like . (dot) but it does not print a space after numbers. | ||
| + | |||
| + | == NIP | ||
| + | : NIP SWAP DROP ; | ||
| + | |||
| + | This command drops the element under the top of stack. if the stack is '' | ||
| + | |||
| + | == PERF | ||
| + | PERF ( -- n ) Performance timer (ms since page load) | ||
| + | |||
| + | PERF pushes the ms since system start onto the stack. Should be accurate to at least 1ms. | ||
| + | |||
| + | Also see: MS, TIME& | ||
| + | |||
| + | == RROT | ||
| + | Bitwise rotate right. | ||
| + | |||
| + | Also see: LROT, LSHIFT, RSHIFT | ||
| + | |||
| + | == RSHIFT | ||
| + | Bitwise shift right. | ||
| + | |||
| + | Also see: LROT, RROT, LSHIFT | ||
| + | |||
| + | |||
| + | == TIME& | ||
| + | TIME& | ||
| + | |||
| + | Pushes the time and date to the stack. Useful! | ||
| + | |||
| + | Also see: DOW, MS, PERF | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ----- | ||
| + | |||
| + | //More coming soon!// | ||
