≡ Menu

Forth Hello World Example: How To Write and Execute Forth Program on Linux OS

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 ------
Add your comment

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book