Incidental Compiler: An Accidental #lang mini-forth in Racket
A three-file Forth dialect generated by accident from a single query, compiled from real
Racket into browser JavaScript via RacketScript, installable via raco pkg install,
and set against the deeper craft of writing an interpreter by hand.
I. Accidental Language Synthesis
Language synthesis has grown quiet enough to happen by mistake. Reading a
Hacker News thread
on
Inside PyPy: First Contact with RPython,
a quoted remark lamented that there is no good host language for implementing another
language. The passing thought was simple: isn’t Racket made for that?
One query typed into Google AI Mode —
implement stand alone non lisp language racket like forth or standard ml
(shared transcript)
— returned a three-file #lang mini-forth collection
(info.rkt, lang/reader.rkt, main.rkt) with a
custom token reader, a runtime data stack, colon word definitions
(: ... ;), and six primitives (+, -,
*, ., dup, swap).
The caveat posted in the thread — no idea if it works — proved
warranted: main.rkt exported [forth-colon :] in its
provide clause without ever defining forth-colon, because
eval-tokens intercepted : directly at runtime. With that
single export removed, the design became a serviceable Forth interpreter.
II. Live RacketScript Bench
The bench below is not a JavaScript mock. It runs real #lang racket/base
source (mini-forth.rkt, 398 lines) compiled
to JavaScript via RacketScript (racks on Racket 9.3,
bundled into mini-forth.bundle.js,
128 KB). In Original test.forth mode it executes the
verbatim six-word dialect; in Mandelbrot (ASCII) and
Sierpiński Gasket modes it adds integer division, bitwise
and, variables, comparisons, structured loops, and
emit/cr so the same RacketScript-compiled Forth interpreter
renders both a fixed-point escape-time Mandelbrot set and a 32-row Sierpiński
triangle directly in mini-forth.
Inspect Racket source (mini-forth.rkt & original AI-generated
lang/reader.rkt)
The live interpreter above is compiled directly from
mini-forth.rkt
(#lang racket/base, verified under both native Racket 9.3 and
RacketScript racks). Below is the original 22 November 2026 Google
AI Mode sketch from which it derives, showing the unbound forth-colon
rename left in main.rkt’s provide form.
;; mini-forth/lang/reader.rkt (original 22 Nov 2026 sketch)
#lang racket/base
(require syntax/strip-context)
(provide (rename-out [forth-read read] [forth-read-syntax read-syntax]))
(define (forth-read in) (syntax->datum (forth-read-syntax #f in)))
(define (forth-read-syntax src in)
(define tokens
(let loop ([acc '()])
(define tok (regexp-match #px"\\S+" in))
(if tok
(let* ([str (bytes->string/utf-8 (car tok))]
[num (string->number str)])
(loop (cons (if num num (string->symbol str)) acc)))
(reverse acc))))
(strip-context #`(module forth-mod mini-forth/main (#%module-begin #,@tokens))))
;; mini-forth/main.rkt (core evaluator & 6 primitives)
;; Built-ins: + - * . dup swap | Definitions: : name ... ;
;; Bug in draft: (provide (rename-out [forth-colon :])) referenced undefined forth-colon.
III. From the Browser to Racket & DrRacket
Racket does not require a proprietary archive format for packages: a plain
.zip archive containing a #lang info metadata file
(info.rkt) is a native single-collection Racket package. Once installed,
Racket resolves #lang mini-forth automatically in both the command-line
interpreter and DrRacket.
raco pkg install https://hypertekst.net/forth/mini-forth.zip
Verified with Racket 9.3: the archive ships info.rkt,
lang/reader.rkt, main.rkt, the exact
mini-forth.rkt evaluator compiled above,
examples/test.forth, examples/mandelbrot.forth,
examples/sierpinski.forth, and a companion SHA-1
.CHECKSUM file for raco verification.
Unzip the examples or create any file starting with #lang mini-forth,
then execute racket examples/mandelbrot.forth or open it in DrRacket
and click Run. Remove cleanly with
raco pkg remove mini-forth.
Two free and open-source environments cover both local and browser-side exploration:
-
Racket & DrRacket
(racket-lang.org,
MIT / Apache-2.0) — the official distribution and IDE. Required if you want
to install
mini-forth.zipviaraco pkg installand write multi-file#langlanguage extensions locally. -
RacketScript Playground
(play.racketscript.org, MIT / Apache-2.0) — a free, client-side browser
playground running the same Racket-to-JavaScript compiler that built our live bench.
Browser playgrounds focus on single-file
#lang racketscript/basemodules rather than custom multi-file#langreaders, so you can pastemini-forth.rktdirectly to experiment without installing anything.
Appendix. Hand-Written Craft vs. Accidental Synthesis
Setting our 22 November 2026 one-query sketch beside a deliberately hand-written
interpreter shows the gap between generating a working artefact and understanding the
craft underneath it. Two years earlier, on 16 November 2024, dverlaeckt
published
Writing a primitive Forth in JavaScript on onirom.fr.
Working from scratch in JavaScript and p5.js, the author studied Leo
Brodie’s Starting Forth and Thinking Forth, Richard
W. M. Jones’s literate x86 assembly JONESFORTH, and Brad
Rodriguez’s Moving Forth series (weighing threading models before
settling on Subroutine Threaded Code). That small browser prototype had far deeper
engineering value than our accidental sketch: it became the author’s stepping
stone to building a bare-metal Forth operating system for ARM hardware.
The contrast between November 2024 and November 2026 is stark, though it did not appear
out of nowhere. Long before language models existed, a developer searching the open
web could already land on complete toy language implementations across Stack Overflow,
Ward Cunningham’s C2 Wiki, mailing-list archives, and Usenet groups such as
comp.lang.forth. What changed is the speed and friction of retrieval and
recombination: those decades of hand-written tutorials, forum posts, and literate
compilers now sit inside the training data, letting a single casual prompt emit a
near-working #lang mini-forth in seconds. The machine can hand over the
finished tokens, but the comprehension still belongs only to whoever reads, debugs,
and builds through the seam.
References
-
Hacker News Thread #50604965 — Discussion on
Inside PyPy: First Contact with RPython (22 November 2026).
https://news.ycombinator.com/item?id=50604965 -
Max Bernstein — Inside PyPy: First Contact with RPython
(bernsteinbear.com).
https://bernsteinbear.com/blog/inside-pypy-first-contact-with-rpython/ -
Google AI Mode Transcript (22 November 2026) — Original query and
three-file
#lang mini-forthoutput.
https://share.google/aimode/fkVZsfLxoaayEBQSJ -
dverlaeckt (onirom.fr) — Writing a primitive Forth in
JavaScript (16 November 2024).
https://www.onirom.fr/wiki/blog/16-11-2024_writing_a_primitive_forth_in_javascript/ -
Racket & DrRacket — Official language-oriented programming
distribution (MIT / Apache-2.0).
https://racket-lang.org/ -
RacketScript Playground — Browser-hosted Racket-to-JavaScript
compiler playground (MIT / Apache-2.0).
https://play.racketscript.org/ -
Ward Cunningham’s WikiWikiWeb (C2 Wiki) — Early hypertext
repository of Forth and toy-language implementations.
https://wiki.c2.com/?ForthLanguage