To me it fits in an odd place. It was much hyped/replicated on Micros in the 1980s as it made the Basic implementations on those machines seem very old fashioned. For most users who were already working on minicomputers in languages like C or Lisp, Forth was just a weird riff on stack based languages that had already been considered and discarded. So the general impression on whether Forth was any good or not depended entirely on what else you had programmed in.
Having said that, stack based languages like Forth, PostScript or even xslt are challenging and thought provoking.
Personally, if I wanted to play with a stack based language I'd play with PostScript or xslt as at least you'd have half a chance to use it professionally.
edit: yeah xslt isn't a stack based language but I always thought it helped when learning it to consider it that way
https://www.c64-wiki.com/wiki/Forth
Seems like there might be good hardware support for Forth on the C64
The download I found had a full manual so I might see if I can figure out how to do some kind of graphical stuff.
it's the minimal amount of extra stuff you need to add on top of assembly language to give you recursive subroutines with parameters; structured control flow constructs like if-then-else (ahem, if-else-then), for-next (uh, do loop), and while; user-defined data types; closures (does>); turing-complete compile-time metaprogramming; embedded domain-specific languages; multitasking; and paged virtual memory. all this costs you about 4k of ram and (usually) a 5× slowdown compared to assembly. nowadays some of those are commonly provided by hardware, but forth has them even on hardware and operating systems that don't
in forth you can very easily invoke your assembly code interactively, look at the results, hex-dump parts of memory, script your assembly code, script your hex dumping, script your scripts, and so on. and it makes a fantastic macro assembler if you can get used to the syntax. the built-in repl gives you a built-in user interface, and it also serves as a sort of interactive debugger; you can't step through your code line by line, but you can invoke it word by word, which is pretty close to the same thing
i did this screencast of debugging an integer square root routine in gforth three months ago https://asciinema.org/a/621404 but i should ofer two cautions:
- i'm no forth expert
- if you actually need square roots in gforth you should probably just use fsqrt. 1024 0 d>f fsqrt f>d d. gives you 32 as ahura mazda intended
https://pygmy.utoh.org/3ins4th.html
If you have new hardware with zero tools, I think it is still possibly the quickest path to more sophisticated options.
i haven't tried the 'three-instruction forth' approach myself (which i had misremembered as being due to brad rodriguez rather than frank sergeant) but that paper was definitely a major factor in forming my viewpoint that forth is not really a programming language but rather an interactive environment that happens to have a programming language (a language the 'three-instruction forth' omits!)
you probably do need a fourth 'instruction' in practice: reset, or at least some kind of interrupt that returns you to the interpreter when you're in an infinite loop. usually there's a separate reset pin, though, which leaves memory intact so you can debug what went wrong — or, at worst, set up the thing so you can power-cycle it. usually that goes without saying, but sometimes hardware is physically far away these days...
In its heyday Forth delivered impressive functionality on very small systems. You could have an interactive development system with a command interpreter, editor, assembler, compiler and the application on an 8 bit microcomputer with less, sometimes much less, than 64 kilobytes of memory.
I used an HP calculator in high school and use an HP emulator on my iPhone, so I'm already pretty good with RPN, so the weird syntax is coming fairly natural to me, and it's substantially easier than doing everything in raw assembly.
The most fundamental difference in feel when programming Forth for an application vs C is that you don't have a stack frame. A stack frame is what lets you throw 10 arguments and 20 local variables into a function, because the compiler binds them all to names and you fire away and then it's cleaned up automatically when you're done.
In Forth, you do not want to do that because every stack variable you use, you have to manually bring to the front with stack manipulation words(e.g. SWAP to flip the position of the top-most and second, ROT and -ROT to shuffle the top three). It's a pretty big deal, and if you let that define your application, you're cooked. You can define temporary buffer or register spaces instead and do some load and store from those to the stack to get through the nastier bits of computation.
But in exchange for that, you get some fascinating possibilities to do tacit(point-free) programming instead. That is, because you've removed names from everything except word definitions(which are just sequences of calls to other words), your stack operations now compose together without needing any additional ceremony. And because you can instruct the interpreter to switch modes between "compile" and "execute" at will, you have a Lisp's degree of metaprogramming, so things like strings and formatted numbers are implemented as modes that jump out of the regular interpreter and wait for an end character to show up in the buffer. This extends even to stuff like IF ELSE THEN(control flow is negotiated with the help of a separate stack).
So it's wildly powerful in particular ways, but boring algorithmic code is often just as hard to write as the metaprogramming stuff, because every time, you have to work through your stack positions and try to break it down to a reasonable composition. And by the time you do that, you have a ton of confidence in having written a very exact spec, but also, the thing you did was probably something like "print a fixed point number".
So it's a very good language to use to make you detail-oriented and build up a personalized way of working. It really doesn't lend itself to flinging things around and telling the rest of the team "the code is self-documenting".
As someone born after C and its derivatives took over the world, Forth has always been this "weird cool old language". It seems like Forth was this very beloved language by a small set of enthusiasts, but I'm not entirely sure why.
I also cannot quite tell if it's a high-level or low-level language, though maybe that's the point? It definitely seems like it might be worth learning for the retro computing development world. Is my understanding correct?