The word "+
" adds two integers. It is used like this;
(Words in Forth are delimited by spaces.)
123 456 + . [cr] 579 okWhere [cr] means press "enter", and the emphasised text is the computers response.
The period "." is another Forth word (called "dot"), that prints a number.
*/
", which is a scaling operator. It's
stack comment is
( n1 n2 n3--n4)
, where the result (n4) is n1 multiplied by n2
and divided by n3.
To test this we might try
10000 355 113 */ . [cr] 31415 okand thus discover that 355/113 is a good approximation to pi.
100 9 5 */ 32 + . [cr] 212 okThe converse operation, converting from degrees Fahrenheight to degrees Celsius is left as an exercise for the reader.
(But as a hint, the word to subtract one number from another is
"-
". It's stack comment is ( n1 n2--n3), where n3 is
n1-n2)
Now that you know almost all there is to know about the Forth command line interpreter, and have learned a few maths operators as well, you can return to the contents page, or go on to the next section.