1x Forth by Charles Moore (1999)
ultratechnology.com
ultratechnology.com
This Washing Machine example isn't hard to understand: ": WASHER ( -- ) WASH SPIN RINSE SPIN ;" http://www.forth.com/embedded/swiftx-embedded-systems-7.html provides the rest of the implementation, which is also not hard to understand, and is at least as easy to understand as a corresponding assembly (or C) version would be. But it requires knowledge of the washing machine, which requires reading data sheets and maybe even doing some manual voltage tests, and it requires knowing (or choosing) which pins (or memory addresses) on the program host connect with the washing machine. There's a minimal kernel involved. You have to know what accomplishment it is you even want to achieve (as the Forth program begins with designing the high-level behavior I quoted, then continues by implementing bottom-up from the compiler primitives to meet the design).
I think Forth will be at most as popular as HDL languages are popular. That is, not very. And in both cases the allure of using C (whether compiled to what the embedded system's processor understands or compiled to the primitives of an IP core implementing a whole processor) will be strong, for there are lots of C programmers and C is more-or-less useful in any domain.
I'll spell it out for you: the JVM is the most widely deployed stack machine in use today. The fact that you don't normally program it directly using a stack-machine like interface does not diminish the fact that the concept of the stack machine is very successful. Yes, there are some warts and issues but on the whole it works quite well and it never ceases to amaze me how fast it can be made to work using JIT and other technologies that weren't even around when Chuck did most of his work. The stack machine has been one of the most enduring concepts in programming.
If you haven't programmed the JVM directly then I would invite you to do so, it's lots of fun and you can pull tricks that would be hard to replicate using java.
Now that clojure and other source level languages have been added to the mix there is even more life in the ecosystem.
In short - and to make the point again - stack machines don't need to be the source language to be effective, but if you really want then you can use them that way.
I'm not sure if factor is running reliably on the JVM yet (there were some attempts in that direction) but that would be a fantastic way to unlock the stack languages true potential, a forth like language on a virtual machine with enormous deployment. That could do for the forth family of languages what clojure is doing for the lisp family.
edit: I simply love being downvoted for a gracious reply to a bunch of insults.
But I get that programmers have a mental defect where they try to show how smart they are by compulsively insulting people at every opportunity. But for that to have a chance of scoring you geek points your comments need to be not completely useless.
It seems that many programmers believe that writing 10x the amount of code to solve a "simple" problem in a complex, yet "general" way is somehow a win.
I wonder if that has to do with having a better grasp of the "complex" problem, so you develop a belief that you "understand" the problem, and can therefore "solve" it?
We know from study after study that 10x the code generally means 10x the bugs -- that bugs scale linearly with text on the page.
And yet we still don't want to solve the problem at hand in the simplest possible way. We don't want to specialize our code. We don't want to write 1/10 the code that just does the present job, and does it well.
I'm as guilty as the next programmer, but I wish I understood the impulse better...
Writing a very complex solution appeals because it defers that work until later: "when I decide what I want, I'll just configure it that way." (And then you never decide.) Bonus points for "it will be the fastest/most comprehensive/most modular solution around." You reassure yourself, with one of these fallacious ideas, that "other people will use this for many years."
This is an issue that goes straight to the programmer's ego and purpose as a craftsman - who are they writing code for, what problems they are solving, what is the thing they are going to tout on their resume. They aren't going to be confident or arrogant enough to railroad all projects into minimal, ground-up Forth-idiomatic projects. Most of the perceived brass rings revolve around short-term ideas like a buzzword technology or a new platform or some other obviously overcomplicated and unnecessary thing.
I have tremendous respect for Chuck and have definitely aimed to emulate him more and more, little by little, though I am not a Forth coder and cannot claim to have neared the style he advertises. My most reusable bits of code tell a similar tale, though: Algorithm and data structure implementations. Parsers and compilers. Formats and protocols. In between those, lots of architecture that I thought was a good idea. Most of it unnecessary.
Side note: Format and protocol support tends to introduce a tremendous amount of complexity. The sign of a good format is in how much it manages to limit this "complexiplosion" while still giving users the features they need. One of the things holding me back is my desire to stick to existing formats.
> Likewise the conditionals. In Classic Forth we used IF ELSE THEN
> And I have eliminated ELSE.
> I don't see that ELSE is as useful as the complexity it introduces would justify. You can see this in my code. I will have IF with a semicolon and then I will exit the definition at that point or continue.
He also highlights why people cannot code well in Forth:
> There is something more than the formalism and syntax of Forth that has got to be embedded in your brain before you're going to be effective at what you do.
The average programmer cannot grasp that "thing" that makes you a good Forth programmer.
It's true. How many times have we seen someone share their reimplementation of a FORTH like interpreter? Far fewer times than we've seen people write and share FORTH applications. Why that is, I'll leave as a question for the reader.
We know FORTH works beautifully as an small interpreter. There's no need to keep rewriting it except as an educational exercise. But would any disagree that there is a real need for more applications to be written and shared if the brilliance of FORTH is ever to be truly realized by more than a small group of people? Not necesarily to create some sort of silly "App Store" culture but just to show what can be done with the language. Proof of concept.
It's also fun to implement features conventionally associated with high-level functional languages, such as lazy generators: https://github.com/JohnEarnest/Mako/blob/master/lib/Algorith...