7 ms·
Forth – Is it still relevant?
- Animats 1y 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.
- spragl 1y agoIndeed. Why did grass shears loose out to lawnmowers? The question is misguided, they are two different categories. The interesting question is why Forth lost out to BASIC on the home computers. There were a few that were Forth based, and there were RPL on calculators, so that whole programming paradigm could conceivably have caught on. I wonder how that would have affected other kinds of programming...
- FarmerPotato 1y agoIt caught on with me. TI BASIC and TI FORTH were my first and second programming environments. But FORTH wasn’t going to built-in. I think only Jupiter Ace ever did.
- jng 1y agoyosefk had the ultimate take on this: https://yosefk.com/blog/my-history-with-forth-stack-machines.html https://yosefk.com/blog/my-history-with-forth-stack-machines...
- astrobe_ 1y agoNot really. The article was written 10+ years ago, saying that one cannot use Forth in commercial products, yet Forth Inc. and MPE are still in business.
- xyzal 1y agoI don't know about now but it soon may be :) An interesting project chose it as its lang: https://collapseos.org/ https://collapseos.org/
- Someone 1y agoThe 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?
- astrobe_ 1y agoYes, I observe a 30-40x slowdown with that method on my interpreter. I was perfectly aware of the cost, Anton Ertl had shown in the 90ies that it wasn't the best on Pentium already [1]. The trick is that you can regain 100% the speed of C (or machine code) by native-coding the critical parts. It's pretty much the same cheating method as JIT or calling native code with an FFI, just manual. In this regard, a simple, naive subroutine threaded scheme makes it very trivial to do. Think Lua extensions but even more easy because you don't have dynamic types or GC memory. Seriously, when I look hear that language X is "easy to extend" and I look at it... No, it is not. I have come to the same conclusions as eForth "independently" (I have looked at many Forth systems before making my own, so there could be some influences), except I wasn't interested in compatibility with the standard, so I ditched the counted strings for C's ASCIIZ strings. This makes interfacing with C/C++ libraries as straightforward as you can get. I quite don't understand why eForth goes for C++; I do see its value to parse more complex languages but Forth? I also don't see the value of multithreading. Cooperative schemes usually work well enough and are easier to handle. If concurrency is needed, multiple programs with RPC, shared memory or pipelines are options usually available (some options are more portable than others, though). > So, the question is, how to encourage today's world of C programmers to take a look at Forth. This is a huge mistake. If you make a Forth for others instead of doing it for your own needs, you are doing it wrong. Doing it for yourself, and not being tied by backwards compatibility because you have published your Forth and you don't want to lose your audience, leads to vastly different answers. [1] http://www.complang.tuwien.ac.at/projects/forth.html http://www.complang.tuwien.ac.at/projects/forth.html
- _0ffh 1y agoNo. Chaining subroutine calls is an implementation detail that is not inherent in the language, even if it may be a popular option because it is easy to do. The usual implementation options are subroutine threading, indirect threading, and direct threading.
- tombert 1y agoI 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.
- octetta 1y agoForth is so easy to learn… go for it!
- fjfaase 1y agoI 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.
- iberator 1y agoI 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 :)
- wewewedxfgdf 1y agoCurious, 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.
- drlobster 1y agoI'm very curious to know how it got on with that. I've had Claude Code write me a Forth for a custom CPU and then write applications on top of that. It get's there but unsurprisingly it's nowhere near as fluent in it as Python.
- procaryote 1y agoAssembly language is often more readable, weirdly
- wartywhoa23 1y agoMay I suggest this wonderful playground to everyone interested in both Forth and pixel shaders: https://forthsalon.appspot.com https://forthsalon.appspot.com
- djmips 1y agoSome very clever demonstrations to be found.
- ajb 1y agoWhen 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.
- ofalkaed 1y ago>but they will try to convince you to scorn all other viewpoints How is that not what you are doing? Lay it all out and back up what you are claiming, some of us are willing to hear you out.
- ajb 1y agoOk, if my comment came across as saying to scorn forth, then it was badly written. Chuck Moore is a genius. How many other people created a language, wrote their own semiconductor simulator and ECAD system, and used it to design their own CPU? But, Forth has a strong culture of NIH, and it started with him. Maybe you need a degree of arrogance and self-belief to do the things he's done. Sadly, most people are not such geniuses as to be able to get away with it. What I tried, perhaps badly,to say; is that it's worth learning everything from Forth culture except for contempt for everything that's not Forth. There are a lot of things wrong with common-denominator programming languages, and common-denominator practices; and it can be exciting for a young programmer to join a community which openly expresses the problems and has an alternative view. (This was especially the case 15-20 years ago when C++ hegemony was at its height). But it can easily become parochial. The lesson of Forth for me, is that you can really gain a lot of productivity by ruthlessly removing generalisations and focusing on the exact problem you want to solve; and not being afraid to re-implement stuff in order to do so - if you can do it in a simpler way. I don't think adopting concatenative syntax is necessary to do this; there are too many examples where it was achieved without. Chuck Moore has argued that all programming should adopt this radical simplification approach; this seems to be the case put by the OP (although not explicitly). I don't think it works. Too many tasks require a degree of collaboration which is enabled by the abstractions. Rewriting everything simpler works for a lone programmer, but it means you have to understand everything, and sometimes you just have to interoperate with some system whose complexity can't be refactored away. Take Unicode- Chuck Moore's answer would be "throw away unicode" but most of us don't have that choice.
- nickcw 1y agoI'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.
- antirez 1y agoIn 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.
- djtango 1y agoIf you are familiar with lisp are there still big benefits to going through the journey again with forth? Or is it just more recursion and expression except via a stack rather than a list
- dreamcompiler 1y agoYou learn things with Forth that you don't learn with Lisp. Foremost among these is the relationship between the highlevel language and the underlying computer. In many Common Lisps you can write functions in assembler if you need to, but in a Forth compiler the assembler is right there. In fact if you have a native assembler it's very easy to bootstrap a baby Forth on top of it and then use that baby Forth to build a complete Forth. No C required. The feeling you get from doing this is one of complete mastery of the computation process. It's awesome.
- keyle 1y agoThanks for mentioning your Youtube serie, have you considered doing it in English? The Youtube auto-dub stuff is pretty bad and the subtitles are quite good but hard to follow with all the vim motions on top of it! Your writing is in English and your code comments too... English was not my native language but I'm fluent now. So unless you are targeting specifically the Italian viewers, you would reach many more people in English. Your content is worth being international I feel.
- slim 1y agohave you considered learning italian ? it's not that difficult once you know english
- spaintech 1y agoIt 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.
- codr7 1y agoForth 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.
- meindnoch 1y agoIn my experience Forth is a great match for LLMs.
- johnisgood 1y agoWhich? I did not have much success.
- FarmerPotato 1y agoThere was long ago a fun paper on evolutionary generation of Forth programs. Code was randomly generated until it showed promise of correct answers. When I’ve promoted LLM for Forth, I see words that I have to google, maybe they’re standard somewhere but… The silliest yet was 2LOOP where “2” seems to be a typo it scraped from the internet. I’m gonna expand that suggestion! 2DO … 2LOOP — iterate using double integer
- sweisman 1y agoI wrote the test harness in Forth for a physics experiment launched on the Space Shuttle. https://github.com/sweisman/cass-edi https://github.com/sweisman/cass-edi
- reaperducer 1y agoConsidering the amount of FORTH code in orbit and launched into outer space, I expect the first aliens to discover us will think it's our universal programming language.
- wartywhoa23 1y agoThe name alone, which means "onward or outward in place or space; forward" is perfectly fitting to a language aimed at the stars!
- Woodi 1y agoAnd what aliens could get from that ? Should they maybe worry about interaction with Forthers planet ?
- wartywhoa23 1y agoThey Notation Polish Reverse afraid not if be everything will OK then!
- shrubble 1y agoFitting given that FORTH was first used to control an 11 meter radio telescope!
- whobre 1y agoDecide for yourself: https://skilldrick.github.io/easyforth/ https://skilldrick.github.io/easyforth/
- tdeck 1y agoThis 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?
- binary132 1y agoYou seem to be presuming here that wanting FORTH to be popular even crossed the minds of the 1201 FORTH developers in question. :')
- tdeck 1y agoAt least this author wrote the following: > So, the question is, how to encourage today's world of C programmers to take a look at Forth. How do we convince them that Forth can be 10 times more productive? So they are clearly interested in getting people to view FORTH as a productive choice.
- binary132 1y agoI’ll amend my first comment to say 1200, then.
- ErroneousBosh 1y ago> but if you actually want the language to become popular why not look at things every other popular language has? Because that is completely missing the point of what Forth is. It's meant to be a simple high-level language that stays quite close to the underlying machine and can be implemented in a few dozen lines of assembler to solve a specific problem you have. It doesn't need to be some massive bloated ball of mud and straw like ultra-high level languages such as C, where every aspect of the underlying machine is abstracted away in library after library.
- MangoToupe 1y agoThe neolithic is still relevant ffs
- K0balt 1y agoI 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?
- rerdavies 1y agoLLMs don't really seem to have any problem writing code in C++ or javascript or Python.
- Razengan 1y agoI swear in 2600 AD we’ll still be asking the same of C++
- 1vuio0pswjnm7 1y 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
- kbr2000 1y agohttps://www.ioccc.org/1991/brnstnd/index.html https://www.ioccc.org/1991/brnstnd/index.html
- bobsh 1y agoForth 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.
- agumonkey 1y agoI 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
- NetMageSCW 1y agoSurprised 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.
- tliltocatl 1y agoIMHO, 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.
- HackerThemAll 1y 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?
- logiqub 1y agoPopularity is a poor judge of quality. But if you meant that the author used more C/C++ than Forth itself, you do have a point. I wouldn't respect a system programming language that can not be used to implement itself (bootstrap). That's exactly the reason why I didn't start to publicize my own. But if you want to know, there is a language named 8th that you can use to make multi-platform applications. In my book, that would be proof enough that it can be done. Now, can it be done productively ? Is the 10x claim verifiable ? That depends on your skill. Maybe it's not for everyone's taste. If you prefer to let the compiler do the compiling for you, maybe not. But that being said, Forth makes you more productive because it allows you to change the problem. Modern environments are bloated and waste so many resources. Libraries are huge, software is huge. One user only require 10% of the functionality, yet you pay for all this fat. When you do real Forth, you do away with the unnecessary... to the extreme. You also change the compiler and the syntax, when it doesn't map to the problem you are solving. With Forth, you can change the problem. Other programming languages can't do that.
- vaxman 1y agoTFA 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.
- timonoko 1y agoHey @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.
- oakpond 1y agoI 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.
- logiqub 1y agoI have been working on Forth for a long time, way before it got popular again as can be attested by the linked GitHub repository (I started in 2014, and published my compiler in 2018). To be honest, for me, it's the best programming language, especially for working solo, or a very small team. But the problem with Forth is that it's an evolving language. You design the language to describe your problem. As a result you need to be a good enough programmer to design a programming language, and make use of Forth's strengths. The other problem is the lack of object oriented features, if they are needed for your project. Because you invent the features as you go, and because you are free to redefine keywords, the final language might be anything. The lack of standardization hurts when it comes down to working on a large team. The biggest problem however, is that you need to discard everything you thought you knew about programming to really do Forth. Real Forth does away with the abstractions common in mainstream languages. Forth is small, fast, portable. I am now working on building my own game engine to prove that Forth is the "ultimate" language (for my needs). Imagine not having to read "The dragon book" to make your own compiler, that's a game changer. And let's not forget we are in the age of "IOT". Changing the syntax on the fly, not having to deal with a compiler that insults (looking at you C++), it's a pleasure. I rewrote my compiler at least 20 times, and I took no shortcut. C was never used, it's just assembly code, and then adding features, based on a solid core. My own innovation is dot notation because I need objects, hooks in the compiler, so you can compiler alter the parser, error handler, etc. if needed. In the future I will release the new virtual machine, with a few applications, and build a game library over time. If lucky, I may fund my retirement. We will see how it goes.
- logiqub 1y agoI realized I forgot to explain why I needed a new language in the first place. So, imagine you work with Python, but you want to work with graphics, and make a game. Python is slow (even with Cython). You find LuaJIT, and it's a blast. Then LuaJIT is no longer maintained, and the official Lua goes in another direction (fractured ecosystem). You lament and despair, you search for a C interpreter. You find Tiny C compiler from Fabrice Bellard, but you don't have his skills. Only hope ? Make your own Python-like language that runs as fast as LuaJIT. That's what a custom Forth implementation can do for you. Honestly if Charles Moore didn't invent Forth, and I hadn't found it about it when I did... I don't know what I would do today. The freedom to express your thoughts exactly the way you want, and not how the compiler tells you to, is liberating. My website has been down for a while, but there are still some snapshots of my previous work. I didn't want to upload to GitHub and be pressured by users, when my design isn't polished yet. https://web.archive.org/web/20220818170224/http://logiqub.com https://web.archive.org/web/20220818170224/http://logiqub.co... https://web.archive.org/web/20240226001954/http://logiqub.com/learn https://web.archive.org/web/20240226001954/http://logiqub.co...