A Forth command is executed by executing all the words in the command one after the other, from left to right. The postfix notation is merely a direct result of that. Here's an example:
3 2 +
The "3" pushes a 3 on the stack. The "2" pushes a 2 on the stack. The "+" pops two values and pushes the sum of those. All three words together have the combined effect of pushing a 5 on the stack.
Notice that the three words don't have to go on the same line. It works just fine like this too:
3
2 +
Note that the meaning of the second line is "Increment the top stack element by 2".
Let's combine this second line into one word:
: IncBy2 2 + ;
The colon indicates the definition of a word, the IncBy3 denotes the name of the new word, and the semicolon denotes the end of the definition.
So now all the following lines have the same meaning:
5
3 2 +
3 IncBy2
1 IncBy2 IncBy2
You can visualize IncBy2 as a function with one parameter and one return value. Usage: Put all the parameters onto the top of the stack, then call the function, then the top of the stack is the return values.
By the way,
here's a reference for all MineOS commands.
Advanced example:
: SumProd OVER OVER * -ROT + ;
This function takes two arguments and returns their sum and product. In Forth terms, this word replaces the first two stack values with their sum and product.
Example:
3 4 SumProd . .
This prints 7 and 12. Here's how it works in detail: This is our stack at the start of the program.
Note that it's empty. Now 3 is called.
3
The stack contains a 3 now. The 4 is called subsequently.
3 4
The stack contains a 3 and a 4. Note that the 4 is on top. Now SumProd changes the stack to:
12 7
A . is called and displays the output 7 (which is also removed from the stack).
12
Finally, the other . is called and displays the output 12. The stack is empty again.
Now if you were wondering how exactly SumProd changes the stack, look no further:
The SumProd needs two function arguments (also known as stack elements) to work correctly. Let's make them 3 and 4, as in the previous example.
3 4
The first word of SumProd is an OVER, which takes the second-to-top stack element and pushes a copy of that onto the stack.
3 4 3
The second word is another OVER.
3 4 3 4
Now there's a *. It takes the topmost elements and replaces them by their product.
3 4 12
The next word is -ROT. It moves the topmost stack element under the next two.
12 3 4
Finally, the + is called, replacing the topmost two elements by their sum.
12 7
And that was all there really is to it.