Skip to content
ALB Wiki

Forth

This is an old revision of this page — revision 3 (2026-10-13 23:35:36 UTC). It may differ from the current revision.

Forth

Forth is a stack-based, concatenative programming language built around two radical simplifications: all data moves through a pushdown stack, and the language has essentially no syntax — source text is a stream of words separated by spaces, each word either a command to execute or a number to push. What sounds like a calculator gimmick turns out to be a complete philosophy of computing: a Forth system is simultaneously an operating environment, an interactive shell, an assembler, a compiler, and the language itself, traditionally fitting inside a few kilobytes. It is the only major language in which the distinction between "features of the language" and "programs the user wrote" is deliberately meaningless — every new word a programmer defines becomes indistinguishable from a built-in.

Forth is also a genuinely strange survivor. It was invented to steer a radio telescope, commercialized by the smallest software company imaginable, standardized three times, shipped inside Sun workstations' boot firmware, disguised inside every PostScript printer, and flown aboard spacecraft — including, by several accounts, ESA's Philae comet lander, whose central processor was a radiation-hardened Forth machine. Half a century after a file system's five-letter limit truncated its name, Forth remains the language of choice when someone has to make bare hardware do something with almost nothing.

A name shortened by the filesystem

The IBM 1130 at the Computer History Museum — the machine whose five-letter filenames turned FOURTH into FORTH (photo: ArnoldReinhold, CC BY-SA 3.0)
The IBM 1130 at the Computer History Museum — the machine whose five-letter filenames turned FOURTH into FORTH (photo: ArnoldReinhold, CC BY-SA 3.0)

Forth's inventor, Charles H. "Chuck" Moore, spent the 1960s as a freelance programmer carrying the same private toolkit from job to job: a small interpreter, a pushdown stack, and a terse command language he had been evolving since writing an Algol-related interpreter at Stanford and at the Smithsonian Astrophysical Observatory.[1] The moment the language acquired its name came in 1968 at Mohasco Industries, a carpet and furniture manufacturer in Amsterdam, New York. Moore was writing a pattern-design program on an IBM 1130 — a 16-bit minicomputer with 8 KB of memory and a disk drive.

Moore intended to call his software FOURTH, as in "fourth-generation" — a layer above the assembler, Fortran, and Cobol worlds it replaced for him. The 1130's file system, however, accepted only five-character filenames. FOURTH became FORTH, and the pun proved durable: forth, moving forward.[2] The name is therefore not an acronym, and the correct capitalization is an ordinary noun — Forth — though the all-caps FORTH lingers from an era of all-caps machines.

The telescope years

The telescope Forth steered — NRAO's 36-foot dish on Kitt Peak, upgraded to 12 meters in 1984 (KPNO/NOIRLab/NSF/AURA, CC BY 4.0)
The telescope Forth steered — NRAO's 36-foot dish on Kitt Peak, upgraded to 12 meters in 1984 (KPNO/NOIRLab/NSF/AURA, CC BY 4.0)

The language found its defining laboratory at the National Radio Astronomy Observatory. In 1970 NRAO was wrestling with a problem modern for its time: the 36-foot (11-meter) radio telescope at Kitt Peak, Arizona needed real-time computer control — antenna pointing, receiver tuning, data acquisition, reduction, and display — and the available machines were minicomputers where every kilobyte and every microsecond was spoken for.[3]

Moore arrived in 1970; programmer Elizabeth Rather — who would become Forth's first professional programmer and its chief historian — joined the project in 1971. Together they built a multiprogramming Forth system that ran the telescope around the clock: controlling the dish, reading receivers, and letting astronomers type commands at a console while observations ran.[3][4] This origin matters to everything that follows: Forth was not designed as an academic exercise but forged in instrument control, where interactive development (fix it while the telescope points), tiny code, and direct hardware access were survival requirements. Radio astronomy remained a Forth stronghold for decades — observatory control systems on several continents ran on it.

FORTH, Inc. and the FIG diaspora

The Jupiter ACE (1982) — a home computer that shipped Forth in ROM instead of BASIC (public domain)
The Jupiter ACE (1982) — a home computer that shipped Forth in ROM instead of BASIC (public domain)

In 1973 Moore, Rather, and colleagues left NRAO and founded FORTH, Inc. in Manhattan Beach, California — one of the earliest companies to sell a programming language as a product. Their flagship, polyFORTH, spread across observatories, laboratories, and factory floors; the company's microFORTH (1977) retargeted the system to the new microprocessors — 8080, Z80, 6800, 6502, 6809 — just as the personal computer era dawned.[4]

The decisive spread came from below. In 1978 the Forth Interest Group (FIG) was founded in Northern California and began distributing fig-FORTH: a complete, documented, public-domain Forth model ported by volunteers to nearly every microprocessor of the era, distributed as printed assembly listings that hobbyists typed in.[5] Years before "open source" had a name, a working compiler-interpreter circulated by mail and club library. Combined with Leo Brodie's friendly 1981 tutorial Starting Forth, fig-FORTH made Forth for a while the serious hobbyist's alternative to BASIC: it ran rings around interpreted BASICs in speed, occupied a fraction of the memory, and — unlike BASIC — let the user extend the language itself. The British Jupiter ACE home computer (1982) even shipped Forth in ROM instead of BASIC.

The standards road

Forth's minimalism had a cost: every implementation invented its own conventions. The community's answer was a sequence of steadily more formal standards:

YearStandardWhat it settled
1977Forth-77Informal FIG conventions — stack effects, core word names
1979Forth-79First published standard; the "79-standard" dialect
1983Forth-83Major rework — mandatory changes broke older code; controversial to this day
1994ANS ForthANSI X3.215-1994 (later ISO/IEC 15145) — the modern baseline
1994IEEE 1275Open Firmware — a Forth dialect as boot-firmware standard
2012Forth 2012Community-led revision updating ANS Forth

The 1983 fracture deserves mention: Forth-83 changed established semantics — loop behavior, NOT, division rounding — enough that working Forth-79 code could silently change meaning. Some programmers and vendors simply stayed on Forth-79 or polyFORTH, and the schism taught the community a permanent lesson about breaking a language whose entire selling point is accumulated personal libraries. ANS Forth in 1994 gave the language its durable modern form, and the Forth 200x committee process produced the Forth 2012 update.

The machine model: two stacks

Forth's computational anatomy is two pushdown stacks plus a dictionary. The data stack (usually just "the stack") is where operands live: numbers are pushed onto it, and operators consume their inputs from it and push results back. The return stack holds subroutine return addresses during word calls — and because it is directly manipulable (>R, R>, R@), programmers use it for temporary storage and loop indices.

The data stack — 3 4 + 5 * (TOS is the rightmost cell)
token    stack          what happened
 3       3              push
 4       3   4          push
 +       7              pop two, push the sum
 5       7   5          push
 *       35             pop two, push the product

stack words          ( before -- after )
DUP    ( n -- n n )          duplicates the top cell
DROP   ( n -- )              discards it
SWAP   ( a b -- b a )        exchanges the top two
OVER   ( a b -- a b a )      copies the second cell to the top
ROT    ( a b c -- b c a )    rotates the top three
2DUP   ( a b -- a b a b )    duplicates a pair

The evaluation of 3 4 + 5 shows the entire mechanics: 3 pushes, 4 pushes, + pops both and pushes 7, 5 pushes, pops 7 and 5 and pushes 35. There is never an expression tree, a precedence table, or a register allocator — just last in, first out. This discipline has a formal consequence: a stack forces postfix order, and postfix order needs no parentheses, no precedence rules, and no grammar beyond "words separated by spaces." It is also why two stacks is significant mathematically: a machine with two pushdown stores is already Turing-complete — Forth's model needs nothing else.

Postfix arithmetic and stack effects

The HP-35 (1972) — reverse Polish in a pocket (photo: Holger Weihe, CC BY-SA 3.0)
The HP-35 (1972) — reverse Polish in a pocket (photo: Holger Weihe, CC BY-SA 3.0)

The notation is reverse Polish notation (RPN). Polish logician Jan Łukasiewicz devised his parenthesis-free prefix notation in 1924 to formalize propositional logic; Australian computer scientist Charles Hamblin showed in the late 1950s–1962 that the reversed, postfix form could drive a machine evaluation by stack — the trick that made RPN computable in one left-to-right pass.[6] Hewlett-Packard brought the same scheme to millions of pockets: the HP-35 (1972) and its descendants made "enter, enter, add" the engineer's muscle memory.[7] Forth and HP calculators are the two great carriers of Łukasiewicz's idea into working machinery.

Because parameters live on an implicit stack rather than in a signature, Forth programmers document contracts with stack-effect comments:

The notation ( n1 n2 -- n ) is a comment — the compiler ignores it — but it is the type signature Forth refuses to have, written where humans can see it. Reading DUP ( n -- n n ) as "consumes one, leaves two copies" is the first literacy of the language.

The dictionary and the outer interpreter

Everything in Forth is a word, and every word lives in the dictionary: a linked list of records, each holding a link to the previous entry, the word's name, a code field saying how to run it, and a parameter field holding its data — or, for colon definitions, its thread of addresses. Newest words link to older ones, so the latest definition shadows the rest — you can redefine + if you are feeling destructive, and everything compiled afterward gets the new + while older code keeps the old one.

The outer interpreter (the text interpreter — the thing at the prompt) runs a loop a child could hold: take the next space-delimited token; look it up in the dictionary; if found, execute it (or, in compile mode, append its address to the definition being built); if not found, try to parse it as a number; if that fails, complain. That is the entire parser. There is no separate compilation unit, no build step, no REPL distinct from the compiler — typing : CUBE DUP DUP ; at the prompt compiles a new word into the dictionary in real time, ready to test on the next line. Interactive development — write a word, test a word, never leave the prompt — was Forth practice decades before "REPL-driven development" became a buzzword.

Threaded code: three instructions to run the world

How does a list of addresses become running code? Through the most famous implementation trick in language history: threaded code.

Inside the dictionary — : SQUARE DUP * ; compiled
 LINK      NAME        CODE       PARAMETER FIELD (the thread)
┌──────┬───────────┬──────────┬─────────┬────────┬─────────┐
│ ptr→ │ "SQUARE"  │  DOCOL   │  &DUP   │   &*   │  &EXIT  │
└──┬───┴───────────┴────┬─────┴────┬────┴───┬────┴────┬────┘
   │                    │          │        │         │
   ▼                    ▼          ▼        ▼         ▼
  previous             runs       DUP's    *'s       EXIT —
  word in              docol:     code     code      return to
  the chain            "enter a   field    field     the caller
                       colon def"
NEXT — the inner interpreter (the whole virtual machine)
   W  ← (IP)        fetch the address IP points at
   IP ← IP + cell   advance to the next
   JUMP (W)         and go

   three instructions — the entire execution engine

A colon definition : SQUARE DUP ; compiles to a record whose parameter field is the address of DUP's code field, then 's, then EXIT. A pointer called IP (the instruction pointer) walks the list, and a tiny loop called NEXT does the whole work: fetch the address IP points to into register W, advance IP, jump through W. On many processors NEXT is three or four machine instructions. That is the entire virtual machine.

Moore did not invent the technique — forms of threaded code appear in 1960s software — but Forth made it famous and made it a design: because "compiled" code is just an address list, the compiler amounts to an address writer, the debugger can walk the thread, and the decompiler can reconstruct source. Variants evolved over decades — indirect threaded code (the classic model), direct threaded (code-field addresses inline), subroutine threaded (real call/jsr instructions — what most modern Forths emit), and token threaded (bytecodes — used by Open Firmware). The payoff across all of them is the same: code density that routinely beat hand-written assembler on 1970s hardware, which is precisely why Forth lived in telescope controllers and later in boot ROMs.

Control structures without keywords

Forth has no parser, so it can have no grammar — and famously gets control flow anyway, through immediate words: words flagged to execute at compile time, inside the compilation of another word. IF, ELSE, THEN are not keywords; they are little compiler programs that lay down branch instructions and shuffle the stack of pending fixups:

DO ... LOOP (with +LOOP for strides, I for the index, LEAVE to escape), BEGIN ... UNTIL, BEGIN ... WHILE ... REPEAT, and CASE ... OF ... ENDOF ... ENDCASE cover structured flow — with the condition before the IF, which startles newcomers but is just postfix logic again: push the flag, then decide. Recursion needed an explicit word (RECURSE in modern Forths) because a word under construction is deliberately invisible to the dictionary until its ;.

CREATE and DOES>: the language that makes languages

The feature that lifts Forth from oddity to language laboratory is the pair CREATE ... DOES> — the machinery for defining new kinds of words, not just new words. CREATE makes a dictionary entry with a data field; DOES> rewrites the entry's run-time behavior in Forth itself. With it, CONSTANT is not a primitive — it is a one-line definition:

After : CONSTANT CREATE , DOES> @ ;, writing 42 CONSTANT ANSWER manufactures a new word ANSWER that pushes 42. You have extended the compiler — not with a macro facility or a plugin API, but with an ordinary two-word definition. Arrays, structs, enumerations, state machines, entire DSLs: each becomes a defining word. This is Forth's answer to Lisp's macros, and the same deep idea in different clothes — the language and its metalevel are made of the same material.

Memory, cells, and the absent type system

Forth memory is a flat array of cells — machine-word-sized boxes, typically 16 bits on classic systems, 32 or 64 on modern ones. @ (fetch) and ! (store) read and write cells; C@/C! touch bytes; VARIABLE names a cell; ALLOT reserves raw space. There is no heap, no garbage collector, and — the sharpest edge for moderns — no type system at all. A cell holds a number; whether it is an integer, a character, an address, a flag, or a double-cell integer occupying two cells (2@, 2!, D+) is a convention in the programmer's head. Floating point, where it exists, is an optional word set with its own stack on many systems.

This is not a defect the language apologizes for; it is the price of the ticket. The absence of types, syntax, heap, and linker is exactly why a complete Forth — editor, compiler, interpreter, multitasker — historically fit in 8 kilobytes. Every protection a modern language provides is a mechanism Forth replaces with one word: discipline.

Blocks, screens, and the old-school workflow

Classic fig-FORTH systems had no files at all — mass storage was managed as numbered blocks of 1024 bytes, displayed and edited as "screens" of 16 lines × 64 characters. 3 LOAD compiled screen 3; a screen could LOAD its successors, so a program was a chain of blocks; the editor was itself a few dozen Forth words. Programmers organized an application the way a book organizes chapters: screen 1 an index and documentation, screen 2 utilities, and so on — hypertext by block number. Modern Forths live in ordinary files, but the block lineage survives in old source archives and in Moore's own colorForth, which stores source pre-parsed in blocks.

The philosophy of factoring

Ask Forth's community what the language is for, and the answer is a methodology, not a feature list. Leo Brodie's Thinking Forth (1984) codified it: factor ruthlessly — decompose a problem into words of one or two lines, until each word names a concept and the top-level definition reads like the problem statement.[8] A Forth program well written is a vocabulary: first you build the words to talk about the problem, then the program is almost already written.

Moore's own design aphorisms run in the same direction — "the dictionary is the language"; simpler is always better; if it doesn't fit, factor it again. The result is a language with an unusual property: it rewards the same skill good writers use — naming — and punishes the same failure — a function that does too much.

Forth in space and firmware

ESA's Philae lander — comet touchdown flown by a Forth-native RTX2010 processor (DLR, CC BY 3.0)
ESA's Philae lander — comet touchdown flown by a Forth-native RTX2010 processor (DLR, CC BY 3.0)
A SPARCstation — Forth lived in every OpenBoot ROM (public domain)
A SPARCstation — Forth lived in every OpenBoot ROM (public domain)

Forth's résumé in deployed systems is remarkable for a "dead" language:

  • Telescope control. The origin story never ended — radio and optical observatories ran Forth instrument control for decades after NRAO.
  • Open Firmware / OpenBoot. Sun Microsystems built Forth into SPARCstation boot ROMs; the IEEE standardized it as IEEE 1275-1994, and it shipped in PowerPC Macs, Sun servers, and the OLPC XO-1. Millions of machines ran Forth at every power-on whether their owners knew it or not.[9]
  • PostScript. Adobe's page description language (1985) — stack-based, postfix, dictionary-driven — is Forth's direct descendant, and for years it executed inside nearly every serious printer on Earth.[10]
  • Space. Forth has flown on numerous satellites and instruments, and ESA's Philae lander — the craft that landed on comet 67P in November 2014 — carried a radiation-hardened Harris RTX2010 processor, a silicon stack machine whose instruction set is effectively Forth primitives, running Forth flight software.[11]
  • Silicon. Moore went on to design Forth chips himself: the NC4000, the ShBoom-derived efforts, and GreenArrays' GA144 — 144 tiny Forth cores on one chip (2011).

Dialects and descendants

The Apple LaserWriter — inside, PostScript; Forth's descendant, printing the world (public domain)
The Apple LaserWriter — inside, PostScript; Forth's descendant, printing the world (public domain)
ImplementationEraClaim to fame
polyFORTH1973+FORTH, Inc.'s commercial line; still sold
fig-FORTH1978The public-domain model that colonized micros
F831983Perry & Laxen's fast, popular Forth-83 system
Gforth1992+GNU's free ANS Forth — the standard open-source choice
SwiftForth1990s+FORTH, Inc.'s optimizing Windows/embedded line
colorForth2001Moore's radical minimalism — color replaces punctuation
Mecrisp2010sNative-code Forth for ARM microcontrollers
Open Firmware1994Forth as standardized boot firmware (IEEE 1275)
PostScript1985Page-description descendant — printers worldwide
Joy2001von Thun's purely functional concatenative language
Factor2003Modern concatenative: GC, objects, optimizing compiler

The conceptual descendants matter as much as the ports. Joy formalized what Forth only implied: in a concatenative language, the concatenation of programs is their composition — SQUARE SQUARE literally means the square of the square — giving the family an algebra rather than a syntax.[12] Factor proved the model could carry garbage collection, closures, and a real optimizing compiler without losing the stack.

A timeline of the minimalist empire

YearEvent
1968IBM 1130 at Mohasco — the program named FORTH
1970NRAO 36-foot telescope, Kitt Peak — Rather joins Moore
1973FORTH, Inc. founded — polyFORTH goes commercial
1977microFORTH — 8080, 6800, 6502, Z80
1978Forth Interest Group — fig-FORTH goes public domain
1979Forth-79 — the first standard
1981Brodie's Starting Forth published
1982Jupiter ACE ships — Forth in ROM instead of BASIC
1983Forth-83 — the schism
1985PostScript ships inside the Apple LaserWriter
1994ANS Forth (ANSI X3.215) — and IEEE 1275 Open Firmware
2001colorForth — Moore's minimalist return
2011GreenArrays GA144 — 144 Forth cores on a chip
2012Forth 2012 standard
2014Philae lands on comet 67P — aboard an RTX2010, a Forth machine

Forth today

Forth survives wherever the engineering constraints that created it still exist: hardware bring-up and bootloaders (the FreeBSD loader still speaks a Forth dialect), microcontroller firmware, test and measurement instruments, and anywhere a single engineer must hold the entire system — compiler included — in their head at once. It is taught rarely and loved intensely; its critics see a write-only language that makes every program a personal dialect, and its defenders answer that this is exactly the point: Forth is not a language to write programs in, it is a language for building the language your problem deserves — a word at a time, from the bare metal up, by a person who has to get the telescope pointed before the sky moves on.

See also

References

  1. Moore, C.H., "The Evolution of FORTH, an Unusual Language" — History of Programming Languages II (HOPL-II), ACM SIGPLAN Notices 28(3), 1993.
  2. Rather, E.D., "Forth — The Early Years" (1991) and Forth, Inc. company histories — the IBM 1130/Mohasco naming story.
  3. Rather, E.D., Colburn, D.R., Moore, C.H., "The Evolution of Forth" — NRAO Kitt Peak account, HOPL-II proceedings, 1993/1996.
  4. FORTH, Inc., polyFORTH and microFORTH histories — forth.com company archive.
  5. Forth Interest Group, fig-FORTH Installation Manual (1978–1980) — the public-domain model and port listings.
  6. Hamblin, C.L., "Translation to and from Polish notation", Computer Journal 5(3), 1962 — the stack-evaluation scheme.
  7. Hewlett-Packard, HP-35 documentation (1972) — RPN at mass scale.
  8. Brodie, L., Starting Forth (Prentice-Hall, 1981) and Thinking Forth (1984; online edition 2004).
  9. IEEE Std 1275-1994, Standard for Boot (Initialization Configuration) Firmware — Open Firmware.
  10. Adobe Systems, PostScript Language Reference (1985) — Forth's most successful descendant.
  11. ESA Rosetta/Philae mission documentation and Harris RTX2010 processor references — Forth hardware aboard the comet lander.
  12. von Thun, M., "Joy: Forth's Functional Cousin" (2001) — concatenative combinatory logic formalized.

Quiz

  • Forth's inventor intended to name the language FOURTH. What forced the shorter spelling — and on what machine?
  • At which observatory, and which telescope, did Forth become a real working system in 1970–71?
  • Who was Elizabeth Rather, and what company did she co-found in 1973?
  • What did the Forth Interest Group distribute that made it an open-source project before the term existed?
  • In 3 4 + 5 *, what is on the stack after each token — and what is the final result?
  • What does the stack-effect comment ( n1 n2 -- n ) mean, and why does Forth need it?
  • Why is having exactly two stacks mathematically significant — what does a two-pushdown machine equal?
  • Whose 1924 parenthesis-free notation underlies Forth's postfix arithmetic — and which 1972 calculator carried it to millions?
  • In threaded code, what does the routine NEXT do — roughly how many instructions is it?
  • A colon definition like : SQUARE DUP * ; compiles to what, physically, in the dictionary?
  • Why can't a Forth word call itself by name during its own compilation — and what word fixes it?
  • Write the one-line definition that creates the word CONSTANT using CREATE and DOES>.
  • What three major systems carry Forth DNA: a printer language, a boot-firmware standard, and a functional descendant?
  • Which ESA spacecraft landed on a comet in 2014 on a processor whose instruction set is Forth primitives?
  • Classic fig-FORTH stored source not in files but in what — and at what size?
  • Forth-83 is remembered for what crime against working code?
Show answers

1 — the IBM 1130's five-character filename limit truncated FOURTH → FORTH, at Mohasco in 1968 · 2 — NRAO, the 36-foot/11-meter telescope at Kitt Peak · 3 — Forth's first professional programmer; co-founded FORTH, Inc. · 4 — fig-FORTH — complete public-domain source listings ported to nearly every microprocessor · 5 — [3] → [3,4] → [7] → [7,5] → [35] · 6 — "consumes n1,n2, leaves n"; it is the type signature the language refuses to have · 7 — a two-stack pushdown machine is Turing-complete · 8 — Jan Łukasiewicz (Polish notation); the HP-35 · 9 — fetch the address IP points to, advance IP, jump through it — three or four instructions · 10 — a parameter field containing a list of addresses of other words' code fields, ending in EXIT · 11 — a word under compilation is hidden from dictionary lookup; use RECURSE · 12 — : CONSTANT CREATE , DOES> @ ; · 13 — PostScript, Open Firmware (IEEE 1275), Joy · 14 — Philae (Rosetta mission), on a Harris RTX2010 · 15 — numbered screens/blocks of 1,024 bytes (16×64 characters) · 16 — it changed established semantics (loops, NOT, division rounding) so valid Forth-79 code changed meaning — the community's permanent lesson in backward compatibility.

Categories: History · Languages · Programming
This page was last edited 2026-10-13 23:35:36 UTC by ALB Team. What links here