Question: I would like to understand the basics of how to write and execute Forth program on Linux OS. Can you explain it with a simple example?
Answer: If you’ve never heard about Forth program, read about it in Wikipedia first. In this article, let us review very quickly how to write a basic Hello World Forth program, and run forth program on Linux or Unix OS.
1. Write a Hello World Forth Program
Create the helloworld program using the Vim editor as shown below.
$ vim helloworld.fth \ hello world forth program. .( Hello World!) CR
Note: Comment in Forth starts with \
2. Make sure Forth command line interpreter is installed on your system
Make sure Forth interpreter is installed on your system as shown below.
$ whereis pforth pforth: /usr/bin/pforth /usr/lib/pforth /usr/share/man/man1/pforth.1.gz
Installing forth interpreter
If you don’t have forth interpreter, install it as shown below.
$ sudo apt-get install pforth
3. Execute the forth Program
Execute forth program as shown below.
$ pforth helloworld.fth PForth V21 pForth loading dictionary from file /usr/lib/pforth/pforth.dic File format version is 8 Name space size = 120000 Code space size = 300000 Entry Point = 0 Little Endian Dictionary Begin AUTO.INIT ------ Including: helloworld.fth Hello World! End AUTO.TERM ------