introduction to FORTH

FORTH is one of the most unique and ingenious programming languages ever invented. Interpreting and compiling are unified, the only difference between interpreting and compiling is a flag that controls whether a FORTH word is executed (interpreted) or stored into dictionary (compiled). FORTH has been implemented in 8 KB (eight kilobytes) of memory. In era of microcomputers, FORTH was ideal, functioned as an interactive programming environment. FIG-FORTH, amazingly, was written partly in FORTH inside assembly code.

FORTH is best suited to writing very small programs. Postfix syntax of FORTH requires as much diligence as assembly language requires. Yet programming in FORTH progresses to very high-level code, by being based on words, top-level of a FORTH program will resemble English prose. FORTH provided an interactive programming system, this author once fixed a buggy FORTH word while FORTH program was running.


FORTH documents

  • "FIG-FORTH internals"

    My notes from studying and modifying 8086 assembly code of FIG-FORTH. Describes how FIG-FORTH interpreter executes internally, how interpreting and compiling are virtually the same operation, ingenious solutions used to assemble FORTH interpreter. Also describes modifying FIG-FORTH to have direct-threaded code (DTC).

  • "FORTH pictured numeric output"

    Brief document about FORTH syntax for printing numbers.

  • BYTE Magazine - Volume 05 Number 08 - The FORTH Language (August 1980).

    This is the famous FORTH issue of Byte Magazine.
    It has Charles Moore's article "THE EVOLUTION OF FORTH, AN UNUSUAL LANGUAGE".

  • "Masterminds of Programming: Conversations with the Creators of Major Programming Languages" ISBN-10: 0596515170

    Moore is interviewed in this book in which he discusses his unconventional views of programming.


my versions of FORTH

In 1994...1995, this author ported 16-bit 8086 FIG-FORTH to 32-bit 80386 protect-mode from which three versions were assembled: PCDOS, PCDOS/DPMI, IBM OS/2 Presentation Manager.

Boosted speed of FORTH using Direct-Threaded Code (DTC). 32-bit FORTH versions could multi-task. Version for IBM OS/2 used OS/2 thread model. For PCDOS version, wrote 80386 protect-mode monitor, a micro-kernel, which scheduled FORTH tasks defined as 80386 Task State Segments (later learned TSSs were slow).

FORTH system screen  VFOS (x86 protect-mode monitor) reflecting x86 exception back to VFORTH
FORTH system screen  multi-tasking demo

To draw graphics using FORTH words, wrote bindings to OS/2 Presentation Manager API using EMX GCC. The result was a unique program -- the only OS/2 PM program written in FORTH that exists in this galaxy.

FORTH system screen  FORTH startup on OS/2 with a 64MB (megabyte) dictionary
FORTH system screen  FORTH drawing a Moire pattern on OS/2
FORTH system screen  FORTH drawing color spectrum on OS/2, EPM editor showing code


White Lightning FORTH by Oasis Software

An amazing version of FORTH.

Full webpage is at: White Lightning FORTH & Basic Lightning by Oasis Software

White Lightning FORTH demo screen   White Lightning FORTH demo screen


HES VIC FORTH and F-PC

Ever try to write a non-trivial program in 1KB (1024 bytes) of memory? Certainly can't be done in C++. On a standard VIC-20 with 5KB, VIC FORTH (VICFORTH) is left with only 1KB available for programs as FORTH dictionary. This author bought HES VIC FORTH, a cartridge, for a 13KB VIC-20 (5KB + 8KB expander) in ~1983. Compared to BASIC, FORTH was much faster, didn't exhaust memory, but easy to crash, more difficult to program, yet far more powerful language. F-PC for PCDOS, also written by Tom Zimmer (and others), was notable for being polished, had hypertext documentation (predated WWW/HTML).


commentary/opinion

positive opinion

FORTH threaded-code compilers are tiny -- generally have zero bugs.
FORTH programs are small and fast, ideally suited to microcomputers.
FORTH is interactive, FORTH could function as operating-system.

negative opinion

Writing in FORTH is difficult because of notorious "stack juggling".
FORTH won't scale to large complex software (FORTH discipline frowns upon creating those things).

controversial/undecided

Older FORTH standards specified 16-bit FORTH virtual machine, threaded-code, format of FORTH words. So, by knowing how FORTH words are executed, programmers could tinker with internals of FORTH. Tinkering could be done whether system was 6502, Z80, 8086, etc.

ANS FORTH standard left unspecified the internals of FORTH. Portability and generating machine-code were goals -- same goals as C. That unintentionally created an argument for writing in C instead, since ANS FORTH has lost major advantages FORTH once had with well-specified threaded-code standards. Still, ANS FORTH would be useful as part of the basis for future threaded-code FORTH implementations.

comparisons

Syntax of FORTH is simple. Core FORTH words are precise. Other languages have a hundred quirks and pitfalls in their syntax. In FORTH, there's not a sliver of doubt how = IF ENDIF will execute. In other languages, if obj1 == obj2 is doubtful, will it compare by value or by reference?

quotes

"FORTH remains the language of the pioneers who live on the fringe. As civilization catches up with them ... they move further out on the cutting edge. If this makes you uncomfortable, join the hordes of the mediocre and program in C."
[jax@Cygnus.COM (Jack Woehr), "Re: Multitasking Forth?", comp.lang.forth, 1994/05]