Forth: A New Way to Program a Mini Computer (1974)
articles.adsabs.harvard.edu
articles.adsabs.harvard.edu
In the long run, I continued down that path by writing inference engines in Forth. It's a clean and solid ecosystem. Even today, I think about returning to Forth to see how far I can push it.
Forth, Inc. now has a number of decent books. Check them out at https://www.forth.com/forth-books/ . And the Internet Archive has plenty of FORTH books: https://archive.org/search.php?query=FORTH . And the FORTH Interest Group has links to most everything else: http://www.forth.org/ .
And let me echo the sentiment that it's delightful to have a programming language you could probably implement in a weekend and understand every bit of what's going on under the hood.
This is in contrast to simply having a "simple universal syntax", and I don't know how many solutions that may have in the abstract sense. There are many cellular automata that from a certain point of view have "simple syntax" (at least in the sense of a limited number of symbols and super limited number of ways to put them together) and have universal computation powers, but are not useful in the slightest for human programming. (Not the most common Turing tarpit to get caught in, but this has snared a number of people over the years trying to turn cellular automata into programming languages.) Who knows what other exotic possibilities may lie out there in math space where no human mind has yet even peered. I think there's probably a lot of other things that are mathematically universal computers, but like cellular automata are just too unstable (in the mathematical sense, all small changes to program produce huge changes to output; we humans prefer languages that have that characteristic only in controlled and limited ways) for humans to program.
And dropping the other criterion of "simple universal syntax" of course reveals a rich space of possibilities, notably including every other programming language that isn't Lisp/Forth/Haskell-esque in theoretically being one of the simple universal syntaxes lifted up to being a programming language. (Haskell is one of the other ones, BTW, being "lambda calculus" reasonably translated to a programming language. It isn't purely so but generally neither is a Lisp.)
Forth was created when Chunk applied his knowledge of Lisp to the problem of maintaining a personal library of punched cards which were reusable on whatever weird computer he needed to run them on next.
Great read, highly recommended. I'd go on but this is my second drop of POL in this thread.
(Someone has posted it and it's reached the front page now: https://news.ycombinator.com/item?id=33180796 )
"A Conversation with Manfred von Thun" in Vector, journal of the British APL Association http://archive.vector.org.uk/art10000350
https://hypercubed.github.io/joy/joy.html
Kevin Albrecht’s mirror of Manfred von Thun’s original website for the Joy Programming Language http://www.kevinalbrecht.com/code/joy-mirror/index.html
https://joypy.osdn.io/ (My own project) Here's a flowchart (SVG) for the interpreter loop: https://github.com/calroc/Thun/blob/simpler/joy_interpreter_...
It boils down to quotation as the primary operation, denoted by enclosing expressions in square brackets. Various combinators accept quotes on the stack and prepend (or not) one or more of them to the pending expression under evaluation (like Continuation-Passing Style), and that's it. That's the whole evaluation model.
E.g. "branch" combinator accepts a Boolean value and two quoted expressions and put one of them onto the pending expression based on the Boolean value:
true [ELSE] [THEN] branch
-------------------------------
THEN
false [ELSE] [THEN] branch
--------------------------------
ELSE
Anyway, I've been messing around with it for a few years now off-and-on and I really think it's "something", eh? (Like I'm almost willing to argue that it's status should be something like the other major models of computation: Turing Machine, Lambda Calculus, SKI Combinators, (Others? Wang Tiles?) ... I suspect Joy belongs on that list.)Synopsis of the language Joy - https://hypercubed.github.io/joy/html/forth-joy.html
Indeed, it has a beautiful simplicity like Lisp, expressing any computation with a small number of core concepts.
I don't consider it a Forth, nor does it need to be. Factor is borrowing from Joy, Lisp, and Smalltalk, the result has a very different flavor. Nothing wrong with that.
The closeness to the metal is basic to the Forth experience, doing interesting things in Factor and in Forth uses completely different mechanisms.
I suggest reading Programming a Problem-Oriented Language[0] by Chuck Moore, because it's among the best memoirs by an influential computer programmer, but also to get a feel for what Forth is all about, what makes it distinctive.
I really miss having an innovative, open-source friendly hardware manufacturer like Sun around - they were an extraordinary group of people. (I worked for them for a while in the late 90s, and it really was a great company, with by far the best tech-company culture I've ever encountered...)
Remembering those days always makes me smile. I really enjoyed that work. The language is fun to use, fast to code and execute and as flexible as you want it to be. I made extensive use of it in robotics, including designing and building a networked multiprocessor walking robot controller from scratch. Remember, no Internet, Arduinos or SO; just bare chips, data books and your own creativity.
My first Forth project was on a 6502.
Frankly, I haven't kept up with the Forth community. Back in the day it was really popular in astronomy as well. Lots of observatories used Forth to control their telescopes, etc.
The transition to C/C++ was inevitable for a range of reasons. Finding qualified Forth programmers became really hard at some point. For me the transition happened when a friend of mine asked me to help port a Forth codebase to C. The system was used for DNA sequencing by researchers in the Human Genome project.
It had become very difficult to maintain and evolve the product precisely due to not being able to find good (or enough) Forth coders. I think that was the last large Forth project I completed, which, oddly enough, involved abandoning Forth in favor or C.
I wrote Modula-2 on DOS for the data loggers and Forth for the embedded stuff. Happy days.
"(" should be: Push next word to X-stack
")" should be: pop and execute top of X-stack.
So "(+ m n)" is equal to "m n +"
And "(IF (< A B) (THEN C ELSE D)))" == "A B < IF C ELSE D THEN"
(IF (< A B)) (THEN C ELSE D) looks about right. This is about readability, all else stays the same. You can avoid the minute overhead of "(" by not using it on a critical situation.
(if (< a b)
Would be parsed completely differently from: ( if ( < a b )
The first will have the interpreter look up and execute the words "(if", "(<", "a", and "b)". The second will have the interpeter look up the word "(", which will skip all the text that comes before a ")".I guess Polish Notation wasn't as uncommon in the 70's as it is today, AFAIK pocket calculators used this too. And once you switch your mind over it feels just natural.
Yet what if the result is, your mind has become unnatural?
!!!
> ")" should be: pop and execute top of X-stack.
> So "(+ m n)" is equal to "m n +"
I don't get it, what is the X-stack? Also can you elaborate this example in more details?
s
x +
s 1
x +
s 1
x + -
s 1 2
x + -
s 1 2 3
x + -
s 1 2 3 -
x +
s 1 2 3 - +
x
which should evaluate to 0?I don't see why you would, though. Even in your trivial example "(IF (< A B) (THEN C ELSE D)))" the brackets are unbalanced and even if they were, IF would be executed after THEN and ELSE. When you push a word to the "X-stack" you correspondingly have to push a word to an analogue of a stack in your mind to know what happens when ')' executes. You failed to do this and therefore your example is broken. In idiomatic Forth, you wouldn't have to worry: in most cases you only have to consider the data stack, and in most cases the sequences you just read to your left imply what's on top of that, not what you read ten words back.
Even if it was slightly easier to read than idiomatic Forth (I disagree that it is), in-line comments strike me as more important "shit" than superficial syntax sugar.
(+ 1 2 3) FORTH ?KNOW IF
HONK!
ELSE
FORTH LEARN!
THENForth holds a two unique positions for me: the first developer I met that made over US$100K/year was a Forth developer (25+ years ago). Forth is also the only language where I have met one person who wrote it for a living.
I tried to implement D+, D-, M+ and such by hand, but they failed.
In Joy, everything is a function that takes a stack as an argument and returns a stack as a result. For instance, the numeral '5' does not represent an integer constant, but instead a short program that pushes the number 5 onto the stack.
The compiler was written in C+bison+flex, the interpreter was in Object Pascal. Unfortunately, the sources didn't survive.
Is it still used im some industry?
I suspect gforth is the most common way to get started. Though it has to be said more people probably write forth-interpreters than write serious code using the actual language.
Embedded use might be one of the rare exceptions, as it can be used to give a very lightweight environment.