0.4 Pass arguments to functions

There is no easier way to pass arguments to functions as in 4tH. Functions have another name in 4tH. We call them "words". Words take their "arguments" from the stack and leave the "result" on the stack.

Other languages, like C, do exactly the same. But they hide the process from you. Because passing data to the stack is made explicit in 4tH it has powerful capabilities. In other languages, you can get back only one result. In 4tH you can get back several!

All words in 4tH have a stack-effect-diagram. It describes what data is passed to the stack in what order and what is returned. The word '*' for instance takes numbers from the stack, multiplies them and leaves the result on the stack. It's stack-effect-diagram is:

     n1 n2 -- n3

Meaning it takes number n1 and n2 from the stack, multiplies them and leaves the product (number n3) on the stack. The rightmost number is always on top of the stack, which means it is the first number which will be taken from the stack. The word '.' is described like this:

     n --

Which means it takes a number from the stack and leaves nothing. Now we get to the most powerful feature of it all. Take this program:

     2     ( leaves a number on the stack)
     3     ( leaves a number on the stack on top of the 2)
     *     ( takes both from the stack and leaves the result)
     .     ( takes the result from the stack and displays it)

Note that all data between the words '*' and '.' is passed implicitly! Like putting LEGO stones on top of another. Isn't it great?