Lably
Skip to content

Forth (programming language)

Stack-based programming language

  • 29 min read
  • 8 chapters

Related on Lably

Through De facto and de jure, Free and open-source software and Function (computer programming)

Forth typically combines a compiler with an integrated command shell, where the user interacts via subroutines called words.

Words can be defined, tested, redefined, and debugged without recompiling or restarting the whole program. All syntactic elements, including variables, operators, and control flow, are defined as words. A stack is used to pass parameters between words, leading to a reverse Polish notation style.

For much of Forth's existence, the standard technique was to compile to threaded code, which can be interpreted faster than bytecode. One of the early benefits of Forth was size: an entire development environment—including compiler, editor, and user programs—could fit in memory on an 8-bit or similarly limited system. No longer constrained by space, there are modern implementations that generate optimized machine code like other language compilers.

The relative simplicity of creating a basic Forth system has led to many personal and proprietary variants, such as the custom Forth used to implement the bestselling 1986 video game Starflight from Electronic Arts. Forth is used in the Open Firmware boot loader, in spaceflight applications such as the Philae spacecraft, and in other embedded systems which involve interaction with hardware.

Beginning in the early 1980s, Moore developed a series of microprocessors for executing compiled Forth-like code directly and experimented with smaller languages based on Forth concepts, including cmForth and colorForth. Most of these languages were created to support Moore's own projects, such as chip design.

Uses

Forth has a niche in astronomical and space applications as well as a history in embedded systems. The Open Firmware boot ROMs used by Apple, IBM, Sun, and OLPC XO-1 contain a Forth environment.

Forth has often been used to bring up new hardware. Forth was the first resident software on the new Intel 8086 chip in 1978, and MacFORTH was the first resident development system for the Macintosh 128K in 1984.

Circa 1982, Atari, Inc. used an elaborate, self-running demo written in Forth to showcase capabilities of the Atari 8-bit computers in department stores. Electronic Arts published multiple video games in the 1980s that were written in Forth, including Worms? (1983), Adventure Construction Set (1984), Amnesia (1986), Starflight (1986), and Lords of Conquest (1986). Robot coding game ChipWits (1984) was developed in MacFORTH for the Macintosh 128K, while the Commodore 64 port was written with SuperForth 64. The prototype of Boulder Dash (1984) was implemented in Forth before being rewritten in 6502 assembly language.

Ashton-Tate's RapidFile (1986), a flat-file database program, and VP-Planner from Paperback Software International (1983), a spreadsheet program competing with Lotus 1-2-3, were written in Forth.

The Canon Cat (1987) uses Forth for its system programming.

Rockwell produced single-chip microcomputers with resident Forth kernels: the R65F11 and R65F12.

ASYST was a Forth expansion for measuring and controlling on PCs.

Sign in to keep reading

7 more chapters are free with a Lably account.

More in Computing and communication