Using Forth's Command Line Interpreter
The most common Forth interface is a command line interpreter. Forth recognises a large number of instructions (called "words"). Here we will look at a small selection of them. The word " 123 456 + . [cr] 579 ok Where [cr] means press "enter", and the emphasised text is the computers response. The period "." is another Forth word (called "dot"), that prints a number. Forth has an exceptionally rich set of integer
operators, as it is often used on systems that do not support floating point
very well. An unusual one is " To test this we might try 10000 355 113 */ . [cr] 31415 ok and thus discover that 355/113 is a good approximation to pi. More than one word can be issued at a time, so as an example, to convert from degrees Celsius to degrees Fahrenheit, we take nine fifths, and add thirty two. This can be tested thus. 100 9 5 */ 32 + . [cr] 212 ok The 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
" 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. |