Forth – Is it still relevant?

github.com

111 points by lioeters a day ago


antirez - a day ago

In my YouTube C language course in the latest episodes I'm implementing a Toy FORTH interpreter: I believe FORTH is nice even just for the educational value it contains, and also, together with Lisp, it shows another way to perform computations. In the mind of the novel programmer, being exposed to these different ways to express computation has deep effects even if most of the code will be written, in their career, in imperative or OOP languages.

tdeck - a day ago

This kind of illustrates the biggest problem with the FORTH ecosystem, in my opinion. Approximately 80% of open source development effort seems to go toward building new, slightly incompatible FORTH interpreters to suit the author's own tastes.

Sure, gForth still doesn't have a decent way to make HTTP requests or match a regular expression, but writing libraries like that doesn't seem to be fun for the average FORTH developer, who would rather reimplement a very barebones language environment to address the gap left by the other 1200 FORTHs.

It's not that these projects aren't cool, but if you actually want the language to become popular why not look at things every other popular language has?

sweisman - a day ago

I wrote the test harness in Forth for a physics experiment launched on the Space Shuttle.

https://github.com/sweisman/cass-edi

Someone - a day ago

The article doesn’t mention performance. Because Forth programs basically chain subroutine calls together, it’s a safe bet it is bad on modern hardware with its multitude of caches.

That’s something you could prevent with an advanced compiler that inlines lots of code and carefully tries to put functions often called together in cache lines, but this code doesn’t do that, and if you did, why spend that effort on your compiler if a simple traditional language makes that inlining easier?

ajb - a day ago

When looking at these kind of subcultures, I think the best policy is "learn from them, but remember that they don't learn from you". They may have a unique better take on some aspects, but they will try to convince you to scorn all other viewpoints, and that's always worse than the gain.

K0balt - a day ago

I love FORTH, and wrote a good bit of forth software back in the day. The main problem with FORTH is that FORTH developers are writing FORTH instead of programs. I mean, that’s kind of also how writing programs in FORTH works, TBF.

The problem is that every program is a DSL, so it’s hard to grep unless you built it. It’s a great personal hacking language though.

I often wonder, though, because of the mechanics of context with LLMs, if forth might not be the ideal language for LLMs to write simple tools for their own use?

Could we pawn off the “you should try forth” problem onto AI lol?

nickcw - a day ago

I've always had a soft spot for FORTH. I think the magic of it is how little assembly you need to write before you are writing your FORTH system in FORTH.

So in my opinion this is somewhat antithetical to the idea of FORTH

> 100% C/C++ with multi-platform support. Though classic implementation of primitives in assembly language and scripted high-level words gave the power to Forth, it also became the hurtle for newbies. Because they have to learn the assembly and Forth syntax before peeking into the internal beauty of Forth.

Fair enough to write a core of FORTH in C as a kind of portable assembler but most of the system should be written in FORTH in my opinion, then you can change it from FORTH. As fast as I can see eForth is written entirely in C.

Anyway FORTH is fun, writing your own is fun too and a great educational experience, but despite being a fan, I wouldn't write anything serious in it today. It is much too low level and it has even less memory safety than C!

The elegance of it continues to impress though with functional programming to get the job done and compile time programming to mold the language into that DSL which expresses the problem perfectly.

spaintech - a day ago

It personally feel that Forth if often overlooked as a solution. It’s great for lowlevel embedded work… even on complicated x86 hardware. I also think that people shy away because the tooling is thin and often DIY, but a Forth exokernel plus a single-purpose app can squeeze more from the hardware.

Tethered Forth programming on small devices is an underrated opportunity, IMO. There is also the opportunity to revise the OpenBoot project, I remember the days of automation for deployments at the Bios, it was an amazing tool for massive deployments of Sun T systems in telcos.

tliltocatl - 20 hours ago

IMHO, that's missing out the relevant bit. RPN and stack juggling is a red herring. Being able to bootstrap the system from zero and then turn it into anything is the real distinguishing feature of Forth. The only other language that can do it is Lisp, but Lisp assumes dynamic memory allocation to be the most fundamental operation while Forth doesn't.

bobsh - a day ago

Forth is the first language I ever did anything cool with, circa 1982. First language to do a mandelbrot on a mac (probably). Used it in the enterprise, migrating databases (don’t tell anyone). I highly recommend colorforth to those looking for maximum forth-ness and an amazing tiny runtime. Also, Oberon.

tombert - a day ago

I still feel like I need to learn Forth.

It has always fascinates me how Forth has been historically used for low level embedded programming, but also can be as high level as you’d like. I feel like this isn’t a concept that has really gone away.

agumonkey - a day ago

I found the culture in forth very interesting

    - optimizing the code density (threaded interpretation)
    - the dynamicism was said to allow for numerical optimization not possible in math libs / fortran long ago
      (see J.V.Noble papers, I'm not knowledgeable enough to confirm his claims but i assume they hold some ground)

    - the bare-metal repl feel is also special, as freeing as poking basic on old hardware but with the freedom of lisp in a way
forth sits in the thinking-altering languages land firmly imho
wartywhoa23 - a day ago

May I suggest this wonderful playground to everyone interested in both Forth and pixel shaders: https://forthsalon.appspot.com

iberator - a day ago

I just wrote assembler for my custom virtual cpu. Now i plan to write Forth interpreter or compiler...

IMO Forth is easiest language to implement from scratch, especially on stack based CPUs :)

codr7 - a day ago

Forth make a nice starting point for designing your own interpreters/languages imo. But I find the stack gymnastics quickly get in the way of practical solutions.

oakpond - 6 hours ago

I recommend trying to implement your own Forth in assembly. It's a great educational experience. However, I would not choose to use it in production. It's not a readable syntax. I doubt it will ever catch on for that reason.

jng - a day ago

yosefk had the ultimate take on this: https://yosefk.com/blog/my-history-with-forth-stack-machines...

wewewedxfgdf - a day ago

Curious, I just got an LLM to write a small web server in Forth.

Phew - that is a terse language. I have heard it compared to assembly language and yeah I see that.

1vuio0pswjnm7 - a day ago

"... after working with the [SORTA] language for a while, I guess I can read it pretty easily, but I also think FORTH is a beautiful language)." - djb

whobre - a day ago

Decide for yourself: https://skilldrick.github.io/easyforth/

Animats - a day ago

> With all the advantages, it is unfortunate that Forth lost out to C language over the years and have been reduced to a niche. Per ChatGPT: due to C's broader appeal, standardization, and support ecosystem likely contributed to its greater adoption and use in mainstream computing.

Oh, please. I've written in Forth. It's useful when you have to do a cram job to fit in a really tiny machine. Otherwise, no.

HackerThemAll - 16 hours ago

> How do we convince them that Forth can be 10 times more productive?

Prove that. Record some videos, show me some code and metrics that'll be evidence that I'm getting 10x more productive.

Look at the languages in the repository:

C 50.6%

C++ 47.6%

Forth 1.5% <-----

HTML 0.1%

Makefile 0.1%

JavaScript 0.1%

How does that build credibility?

NetMageSCW - 21 hours ago

Surprised at the lack of mention of RPL and the HP-48,49,50 calculators that use a language superficially similar to Forth for user programming and internally use a threaded interpreter to implement the calculator.

fjfaase - a day ago

I am using a stack based language as an intermediate language for a C compiler I am writing. The language can be mapped to assembly and I wrote a memory safe interpreter for it. Both are not geared to performance as that is not a primary concern for the compiler and tool chain.

xyzal - a day ago

I don't know about now but it soon may be :)

An interesting project chose it as its lang: https://collapseos.org/

timonoko - 8 hours ago

Hey @grok. Can you write FORTH using M5 macro processor?

Thought for 1m 0s

Yes, it's possible to implement a Forth interpreter or compiler using a macro processor like M4 (and by extension, its evolutionary successor M5, which shares similar macro expansion and substitution principles). Macro processors excel at text transformation, making them ideal for generating low-level code (e.g., assembly) from high-level Forth definitions. While no public implementation specifically uses Alan Dain Samples' historical M5 (whose source and detailed examples are scarce), a robust example exists using GNU M4 to create a Forth-to-Z80 assembler cross-compiler. This targets the ZX Spectrum but demonstrates the technique: M4 macros define Forth primitives (e.g., stack ops, arithmetic) as Z80 instruction snippets, handling control flow with label counters for uniqueness.M5, as an M4 evolution, would adapt similarly—its enhanced features (e.g., better argument handling and streams) could streamline expansions, but the core approach (defining words as macro substitutions) translates directly. Below, I'll outline how it works, provide key macro definitions, and show a complete example. This generates human-readable, annotated assembly without peephole optimization but with inline efficiencies (e.g., DUP ADD → _2MUL).How It WorksCore Mechanism: Input Forth code (e.g., : FOO DUP ADD ;) is processed by M4. Macros like DUP expand to Z80 code preserving stack effects (data stack in HL/DE/SP; return stack in HL'/DE'/BC'). Labels use counters (e.g., if100) to avoid conflicts.

Stacks: 16-bit data stack; return address stack (RAS) for loops/recursion.

Compilation: m4 input.m4 > output.asm, then assemble (e.g., with Pasmo for Z80).

Adaptation to M5: Use M5's = for definitions (vs. M4's define) and => streams for output diversion. Argument parsing aligns closely.

Limitations: Uppercase words only; 16/32-bit ints; basic floats via ROM.

Key Macro DefinitionsMacros are modular (e.g., in stack.m4, arithmetic.m4). Here's a selection:Stack Manipulation (e.g., from stack.m4):

  define({DUP},{                ; ( x1 -- x1 x1 )
    ex   DE, HL               ; 1:4       dup
    push HL                   ; 1:11      dup})dnl

  define({SWAP},{               ; ( x2 x1 -- x1 x2 )
    ex   DE, HL               ; 1:4       swap})dnl

  define({DROP},{               ; ( x1 -- )
    pop  HL                   ; 1:10      drop
    ex   DE, HL               ; 1:4       drop})dnl

  define({PUSH($1)},{           ; ( -- n )
    push HL                   ; 1:11      push($1)
    ld   HL, $1               ; 3:10      push($1)
    ex   DE, HL               ; 1:4       push($1)})dnl
Optimization Example: DUP DUP → DUP_DUP for fewer instructions:

  define({DUP_DUP},{             ; ( x1 -- x1 x1 x1 )
    exx                       ; 1:4       dup dup
    push HL                   ; 1:11      dup dup
    exx                       ; 1:4       dup dup
    ex   DE, HL               ; 1:4       dup dup
    push HL                   ; 1:11      dup dup})dnl
Arithmetic (e.g., from arithmetic.m4):

  define({ADD},{                ; ( x2 x1 -- x )
    add  HL, DE               ; 1:11      +
    ex   DE, HL               ; 1:4       +
    pop  HL                   ; 1:10      +})dnl

  define({SUB},{                ; ( x2 x1 -- x )
    or   A                    ; 1:4       -
    sbc  HL, DE               ; 2:15      -
    ex   DE, HL               ; 1:4       -
    pop  HL                   ; 1:10      -})dnl

  define({MUL},{                ; ( x2 x1 -- x )  [Binary long multiplication loop]
    push BC                   ; 1:11      *
    ld   B, H                 ; 1:4       *
    ld   C, L                 ; 1:4       *
    ld   HL, 0x0000           ; 3:10      *
    ld   A, 0x10              ; 2:7       *
    mul_loop101:              ;           *
    add  HL, HL               ; 1:11      *
    rl   E                    ; 2:8       *
-- ETC ETC. Rest of assembly pørn censored.
meindnoch - a day ago

In my experience Forth is a great match for LLMs.

Razengan - a day ago

I swear in 2600 AD we’ll still be asking the same of C++

vaxman - 9 hours ago

TFA had me at "Per ChatGPT:" ROFL

FORTH has been used to control deep space telescopes and planetariums --it's a great way to expose instrumentation for high-level access, but that access might not be human anymore, it could just as easily expose instrumentation to AI agents.

For example, a FORTH page could contain a prompt "Animate a galloping black and white zebra on the attached 64x32 RGB LED matrix, cache the code to do this on a FORTH page called ZEBRASHOW6432." Another could prompt "Run ZEBRASHOW6432 at the top of the hour during weekdays in the Pacific Time Zone." This might involve lifting C drivers from Arduino and CircuitPython for the 64x32 RGB LED matrix driver into FORTH (trivial) and building an MCP-to-FORTH server, but endless fun...

So I guess it's best to stop reading about FORTH and grab an rP0-2W and attach desired indicators, sensors, actuators and transceivers to see for yourself.

MangoToupe - a day ago

The neolithic is still relevant ffs