Retro: A modern, pragmatic Forth
retroforth.org
retroforth.org
Retro is an interesting Forth platform because it has numerous features not present in more traditional Forth systems, such as the ability to create closures and first class literals while still maintaining compactness that would be expected of a Forth system.
It was originally meant for desktop scripting but has been ported to tiny devices like microcontrollers.
It is worth a look if you are even mildly curious about Forth
Jack Woehr (of the ANS Forth committee) and Mitch Bradley (of Open Firmware fame) think it’s old hat[1], so guess not. (They also think it probably won’t work though.)
In general, people have tried a lot of times; there’s a number of postfix Lisps with type systems—Kitten mentioned elsethread, ActorForth[2], etc.; a low-level Forth, as in identidally sized cells on stack and no automatic memory management, I don’t think has been done to completeness (IIRC either Forth, Inc. or MPE have a standing offer for any that’s able to process their legacy code even just for stack checking), but then C wouldn’t be complete by that standard either (and Rust far too limiting).
Honestly I’m not sure how well it would work. In C, you get a great deal of utility out of compound types, and classic cell-oriented Forth kind of sucks at even mildly complex datastructures—they are certainly possible, but being unable to manipulate them as values on the stack makes things quite unnatural. (And that’s where I draw the line between Forths proper and “postfix Lisps” like PostScript, Joy, and Factor, as such manipulation doesn’t seem feasible without some sort of automatic memory management.)
[1] https://github.com/ForthHub/discussion/issues/79#issuecommen...
Calling it that straight out the gate reminds me not to worry too much about it and just get the thing down into a file for future reference, if I derive a 'real' version of anything in there that I intend to both run now and to stay running I'll put that somewhere else (and leave the sketch in place for historical curiosity purposes).
I've seen people recommend C as a way to "get closer to the hardware", but I think we all know that that's not really been a thing for longer than most of us have been alive. Forth, though? Maybe!
https://news.ycombinator.com/from?site=dawn-lang.org
There hasn't been an update in over a year but I hope it's still going because it looked really interesting.
short long
----- ----
* bah ( don't care )
f float
s string
r reference
p pointer
io stream ( file / socket )
a array
h hash
c clause
I'm not a C programmer, and it took a fair bit of help from folks here on HN to get it compiling (it was forked from a 20 year old C source), for which I'm grateful.RetroForth 2021.1 - https://news.ycombinator.com/item?id=26168640 - Feb 2021 (52 comments)
Retro: A Modern, Pragmatic Forth - https://news.ycombinator.com/item?id=19997008 - May 2019 (50 comments)
Retro: Neat use of ports as high-level API from inside a VM (stack language) - https://news.ycombinator.com/item?id=9764962 - June 2015 (1 comment)
We need a new name for this kind of thing[1] because it's not really literate programming - you can't re-order your code blocks in the literate source files and have them come out in the right place in the code source files which is, I think, a key part of it being literate programming. Don't get me wrong - I use this a lot with the various *occos - but it needs a name of its own.
[1] Assuming we don't already have one that I've missed.
Of course Haskell has had its “literate format” since forever (ETA: the Haskell 1.2 report[2], dated March 1992, has a description in an appendix), and it became mildly popular for Haskell blogging when blogs caught on, but its name was always accompanied by a side note that in Haskell you don’t really need to reorder things (kind of true).
[1] https://github.com/jashkenas/docco/commit/9b666b77c476fd76b9...
[1] https://perldoc.perl.org/perlsyn#PODs:-Embedded-Documentatio...
McIlroy also touches on this in his review, though from the other direction:
> Perhaps the greatest strength of WEB is that it allows almost any sensible order of presentation. Even if you did not intend to include any documentation, and even if you had an ordinary cross-referencer at your disposal, it would make sense to program in WEB simply to circumvent the unnatural order forced by the syntax of Pascal.
[1] Of “Knuth v McIlroy” fame: https://homepages.cwi.nl/~storm/teaching/reader/BentleyEtAl8...
(Though, writing a function long enough that you might want to declare a variable part-way through it would probably be a code smell in Forth...)
There’s an old tradition of annotating Forth code with documentation: code would go into even-numbered 64x16-character “blocks”, accompanying documentation into odd-numbered “shadow blocks”, and on e.g. a VGA you could even view them at the same time.
Bootstrapping new hardware. Industrial control (real time). Firmware. Compilation target.
In that sense it is actually much more like LISP than most other languages, it is scaffolding that allows you to build a DSL (in FORTH probably in the most literal sense of the word(s)).
The programming styles list-first and array-first languages encourage are sufficiently completely different that using them interchangeably tends to be a really bad idea, and honestly python's arrays being named that way irritates me even if I don't consider 'this irritates me' to be a criticism per se.
For instance, in computer science "literal constant" has a very specific meaning.
Python calls things "literals" that are obviously not literals; for instance [1, 2, 3] is actually a constructor which allocates a new li^H^Harray each time it is evaluated.
A true literal does no such thing; its syntax retrieves an object which has been placed into the program image; it typically exists before the program even starts.
Programs depend on the semantics of [1, 2, 3] making a new object each time; a Python compiler cannot just deduce that because all arguments are constants, it can be turned into a literal.
You don't want to learn computer science terminology (or computer science at all) from Python.
This isn't to say that FORTH is going to be particularly -suited- to writing something like a todo app, and I'm having the sort of day where I can see the rough shape of the required code in my head just fine but cannot for the life of me convince my fingers to produce you a useful example, but it's very much doable.
They probably tell you to use another programming language because if that's the kind of questions you are asking for your todo list application using another programming language is likely going to work better for you. It's a bit like asking to provide the schematics for a particular type of wrench when your job is to put a nail in the wall.