80 points · by UkiahSmith · 7y ago · 50 comments
It comes bundled with the C++ based JUCE GUI framework, SQLite, ODBC, encrypted binaries, JSON support, and a lot of support for other things that you typically don't see in a tool written by one person. The more expensive licenses come with AWS and automotive Linux support, so nifty for this area.
Sadly, it is closed source and commercial (although you can get source with an enterprise license I think). On the plus side, it is really cheap (there is a free version too I believe) and the main developer seems to add user requested features and fix bug reports very quickly.
I obviously wouldn't write a production system in it (although I'm sure you could), but I wouldn't mind having a fun REPL based language to write simple and easy to distribute cross-platform desktop apps.
"An elegant weapon for a more _civilized_ age"
It is the forth of choice for any serious forth developer.
I'm unlikely ever to learn forth, but if there are general lessons to be learnt from the mistakes made, I'll learn from them. So, what are those mistakes? (thanks)
High-level, what makes Forth interesting? What are it’s major strengths and weaknesses?
followed by a part written in FORTH: https://github.com/nornagon/jonesforth/blob/master/jonesfort...
It builds gradually from asm primitives into a somewhat sophisticated language with features like exceptions, function inlining and a decompiler.
The major strength, probably unique amongst programming languages, is that you can keep the entire system in your head (by "system", I mean both language and the simple operating system that it implements). The downside is that the code is write-only.
I've used that to build a FORTH interpreter on an AVR micro.
Small Forths can be totally understood by the programmer (perhaps just a few pages of code for their kernel), but still be expressive enough to actually use. Applications written in Forth are typically deeply entangled with the interpreter. You can't separate a "program" from the environment.
It's more like a collection of ideas and design principles than one singular language. Most Forth programmers write their own implementation, or several. You can decide what indulgences you want. (I like having "quotations"- inline anonymous word definitions like Retro has- and special-cased string literals. I also have my own style of looping words that aren't quite like ANS Forth.) This also means Forth code can never be dropped into another project and directly re-used: you can only take ideas.
Starting from a blank page every time, carrying with you ideas and writing code afresh is a good way to travel light. Self-reliance. Building human-scale programs. No one would write a web browser, or an Oracle-compatible SQL engine, in Forth, because a Forth programmer wouldn't have much of a use for those things. Solve only the problems you really have, with as little code as you can manage.
Forth is unique as it is probably the only serious language that you can write production systems in and understand the entire compiler/interpreter, parsers, data structures, and functions (called words).
Everything is pretty simple. You could use C as the base, but traditionally you would write a few dozen assembly routines and link them together and form some core words to manage a stack (there are 2 stacks and that is it) and make more complex words.
It gets a lot more deep, but Forths aren't really for me. If I'm going to use something weird, I'll write some APL.
I'm nowhere near your level of comprehension in either language, but agree that spending some time outside of curly brace land gets you more comfortable with other languages.
In a stack based language those aren't interesting ideas, they're just naturally emergent.
The other thing is that it makes it utterly trivial to pull out or insert code in a function. allowing for some radical refactoring.
Strengths: Lisp-level metaprogramming facilities while also being extremely fast and close to the metal. Weakness: the Perl problem (write-only) but worse.
Like assembler, Forth is untyped.
These failings could be at least partly forgiven if Forth was fast. But it isn’t, because most words are short and all the stack manipulations are done with subroutine calls. It’s possible to write an inlining, optimizing compiler, but then the simple layout of code in memory is lost, and quick introspection using a memory dump becomes nearly impossible.
But, it is a neat tool to bootstrap a working system quickly on new, embedded hardware with limited resources. Definitely a black belt tool for lightweight systems written by a single person. Hard on maintenance programmers.
See Jonesforth for a tutorial example.
I wrote a Forth a few decades ago. The insight gained reminds me of Nand2tetris, but the latter is far more mainstream.
This can have an advantage: one can stuff much more code (and functionality) in a very memory limited system (e.g. smart cards), especially with WORDS compression:
"Huffman threaded code is one of the most compact representations known for a computer program"
https://en.wikipedia.org/wiki/Threaded_code#Huffman_threadin...
Depends on who is the writer...
> There are also no local variables in standard Forth
Named locals variables are in the standard, as an optional extension. Because not everyone want them.
> you have to push (and pop!) them from the separate return stack
That's the main reason why the return stack is exposed to the programmer, yes, but there are other techniques like putting some of the data that are used throughout the program in (global) variables. you generally choose depending on how much simplification you gain and how much modularity you lose etc.
> Accessing parameters is done by manipulating the stack, which makes the code opaque after a year or so
Depends on how you write and comment.
> Named constants and variables are all global. So, it is very difficult for a team to use
Standard Forth as vocabularies to isolate functions, constants, and variables that is supposed to help with name clashes. Many variants like Retro have some sort of namespace mechanism.
Did you actually use Forth in a team context?
> These failings could be at least partly forgiven if Forth was fast. But it isn’t, because most words are short and all the stack manipulations are done with subroutine calls
Not a problem, because you design your programs to minimize stack juggling. Less overhead, more readable, one stone, two birds.
My dialect which uses very naive subroutine threading (it just executes lists of function pointers) can rival with Lua (non JIT) on certain tasks because my Forth doesn't spend its time doing useless stuff like looking up an hash table.
The speed of Forth is not in its bytecode interpreter. It's in the simplifications it encourages.
> It’s possible to write an inlining, optimizing compiler, but then the simple layout of code in memory is lost, and quick introspection using a memory dump becomes nearly impossible
I have written a few decades such a thing for the 8086, and I would say the lack of introspection was never a problem. When you write such a system, the hex machine codes sticks quickly in your head. I think I wrote a disassembler for the lulz, but an hex dump was probably my main "introspection" tool.
> I wrote a Forth a few decades ago
I wrote several Forth systems in the last few decades. The latest one I wrote is my goto-tool and serves me almost daily.
You could use lambda notation to name the parameters of a function, while still preserving postfix function application as in FORTH. This would effectively give you De Bruijn notation, in which named lambda was often denoted `[var] expr`. Though, ironically, De Bruijn is also known for his "nameless" De Bruijn indexes, which dispense with the very naming of function parameters, replacing these names with what are in effect references to positions on some abstract argument stack.
Not even close. Rather more like macro-assembler-level metaprogramming facilities.
Ultimately a language is there to make programming a CPU easier. If you believe in just absolute minimal complexity, FORTH is what you get when you find this intersection of leverage vs. minimal tolerable complexity. A FORTHer generally doesn't believe in writing device drivers so much as writing maybe 20 lines of code yourself that twiddle the registers to get done what you want. You're basically told to ask yourself over and over again "do you really need that?" The answer is usually "well I might need it tomorrow... maybe..." but in software, requirements change so fast that the abstractions we design for what we think we might need tomorrow don't actually match what's actually needed. The FORTHer solution isn't to just continue generalizing until you have a fully galaxy brain interface that could accommodate anything the future could throw at you-- it's just to not generalize at all, and to put the weight of working in a system with less abstraction on the programmer. The bet is that the weight of dealing with less abstraction is less weight than dealing with a tower of abstractions that were built for the wrong requirements.
I don't know if I fully buy it, but it's worth trying to think like a FORTHer as an intellectual exercise to make you a better programmer.
In a typical non-Forth "stack VM", there is a single stack which behaves like the C stack: allocate an activation record with locals on a function call, pop the whole thing off at the end. Intermediate calculations go on top of all this, avoiding the need to explicitly register allocate in bytecode, but operands don't naturally flow between function definitions; they're copied around explicitly as the stack grows and shrinks.