Writing a primitive Forth in JavaScript (2024) onirom.fr · 14 points · 2 comment...

@best

Writing a primitive Forth in JavaScript (2024) onirom.fr · 14 points · 2 comments · HN thread

TL;DR The author walks through a roughly 100-line Forth interpreter written in JavaScript, using the p5.js framework for a graphical CLI. It supports only ':', ';', '+', '-', '.' and 'words', and the article explains its dictionary, word search, word call, tokenizer and compile-mode logic. It serves as an introduction to a planned series on a baremetal Forth OS.

  • Forth is a stack-oriented, concatenative, reflective language by Charles H. Moore, used in calculators, games, 8-bit computers and embedded systems.
  • The prototype has two core structures: a data stack of numbers and a dictionary of words, each holding a list of functions and an immediate flag.
  • Word lookup searches the dictionary backward so newer definitions override older ones.
  • In compile mode, evaluated words are appended to the newest definition; unknown tokens are parsed as numbers and compiled as push calls.
  • The author's ARM Forth dialect has about 70 primitives and grew from this prototype, which ran on an RPi Zero.
  • The article notes that a practical Forth needs stack operations like dup and drop, plus loops and conditionals, which can be added as words.

Discussion The thread is very small, with only two comments. One remark, from bitwize, is a nostalgic joke that writing things in a programming language now feels like the quirky old-internet charm of Flash games. The reply from pjmlp is more pessimistic: they expect LLMs to make the earlier 4GL vision real, and they point to iPaaS products and code generation that reads like minified C or IOCCC entries. The mood is wry and reflective, with no real technical debate about Forth itself.

  • Hand-built language projects now feel nostalgic, like old-internet hobby culture (some): One commenter compares writing a programming language for fun to the quirky charm of Flash games, suggesting it now belongs to a past internet era.
  • LLMs will make high-level code generation the norm, with hard-to-read output (a few): One commenter expects LLMs to finally deliver the 4GL vision, pointing to iPaaS products and code generation that is as hard to read as minified C or IOCCC entries.

#Forth #JavaScript #Interpreters #ProgrammingLanguages #Retrocomputing #BaremetalOS