Implementing a Forth

https://news.ycombinator.com/rss Hits: 12
Summary

I think one of the most interesting questions in the Forth universe is how small can its core be? Which is to say, how few words do you need to implement in a host language (or raw machine code, as we’ll see) before you can bootstrap the rest of the language in the Forth itself? (The most popular one I’ve seen is SUBLEQ, which stands for "SUBtract, branch if Less than/EQual to zero". And since there’s only one, you typically omit it and your program is just the operands for the implied instruction. The "language", then, has no operations and feels to me like the computing equivalent of John Cage’s musical stunt 4'33" (wikipedia.org).) So I guess a Forth with one word is all you need. Therefore, it’s not a question of, "How few words would be possible?" but rather, "How few words would be interesting?" The answer will be personal to you. The Forth-eV Wiki’s page on "Minimal Word Set" is a great place to start: In addition to the word set, you can also constrain the total file weight of your core Forth. (Or lines of source or some other arbitary limitation.) Some really intriguing minimal Forths I’ve encountered: PlanckForth I love the hexdump visualization of Koichi Nakamura’s PlanckForth: You’re looking at a complete working Forth implementation in the form of a hand-written ELF binary in less than 1,000 bytes. The rest of PlanckForth is written in PlanckForth to implement a "normal" Forth. SmithForth David Smith’s SmithForth is another 1,000 byte, hand-written machine code Forth that bootstraps a more complete Forth. "My goal with SmithForth is not to stop writing machine code early, but to start writing Forth early." sectorforth Cesar Blum’s sectorforth is even smaller, at 512 bytes (the size of a boot sector). Like other ultra-tiny Forths, it starts with just a handful of Forth primitives with which to bootstrap higher-level constructs. The included 01-helloworld.f example is 200 lines of well-commented Forth source which starts with making numbers, implements a ...

First seen: 2025-06-03 11:40

Last seen: 2025-06-03 22:43