163 points · by Drakonis · 3y ago · 57 comments
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...
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!
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.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).
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.
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.
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...)
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...
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)).