Live data from Hacker News

What the hell is Forth? (2019)

blog.information-superhighway.net

91–100 of 138 posts

Re: What the hell is Forth? (2019)

#91
post #89

Of all those what is forth articles I've read, this has been my favourite read. Forth is an interesting language, but as a web dev, I've never realised its potential to be a useable language. However, I recently got a RP Pico, and was looking for a language to control it. Browsing the available ones, I saw a demo of a forth and the way it was used kind of blew my mind as it kind of connected the understanding of the…

I think Forth reinforces that even more than machine assembly language does. It’s all just numbers and some ops, also encoded as numbers.

Re: What the hell is Forth? (2019)

#92

Wait! Is core Forth smaller than core Scheme?

You can write a Forth-like in a few lines of a modern language and then keep expanding it. There are Forths for the smallest systems and challenges of minimal instruction set Forth, like [0].

The article [0] explains what people (and myself) are really happy about having this around:

> Let's pretend I've wired the 68HC11 so that port A pin 01 controls an LED. I can't remember whether a 0 or a 1 turns it on and I'm not sure whether it works. I look in the data book and find that address zero is the port A data address. Although the LED only uses a single bit of port A I don't have anything else connected so I'll just set the whole byte on or off and see what happens.

Without that, embedded work is far more annoying. And I do like the way it works; every so many years, I start implementing my own to figure out if it's really not possible to make something modern [1] (written to play around with Xamarin apps and ASP.NET servers without having to wait 9 hours for the compile & deploy to finish, so in the spirit of Forth indeed) with it which always falls over on stack manipulation, which gets incredibly annoying when programs grow; you waste so many instructions just to line up the stack correctly to execute a some more complicated word. We currently have a hybrid language (hopefully released this year) with datatypes, stack, (reactive) variables etc, but that is getting rather huge (for a Forth) and, because of other features we have, it's more like a Frankenlanguage, marrying Forth & Lisp... That works well but not anything usable in embedded or in the spirit of the original Forth, besides spelonking/scripting systems.

[0] https://pages.cs.wisc.edu/~bolo/shipyard/3ins4th.html [1] https://gist.github.com/tluyben/16ee2645c4c8aed813005d51488d...

Re: What the hell is Forth? (2019)

#93

If you want to build a Forth check out R. G. Loeliger's "Threaded Interpretive Languages Their Design And Implementation" https://archive.org/details/R.G.LoeligerThreadedInterpretive... (Jonesforth has already been mentioned.) Read "Starting Forth" and "Thinking Forth" too, even if you don't want to write a Forth or program in Forth. It'll still expand your mind in useful and fun ways.

BYTE magazine dedicated an entire issue to Forth in 1980 (vol 5, no 8). Interestingly, they used the exact same cover image as the Loeliger book, lol:

https://archive.org/details/byte-magazine-1980-08

Re: What the hell is Forth? (2019)

#95
post #77

I started using Forth because I wanted a Reverse Polish Notation calculator at the command line. It turned out to be very practical and extensible. For example, I created many words to perform unit conversion, such as temperature: : 2fahrenheit 9 * 5 / 32 + ; : 2celsius 32 - 5 * 9 / ; Furthermore, I can even pull in live currency conversion rates from Yahoo Finance to go between USD and CAD. Since my underlying Forth…

Reminds me a bit of dc: https://en.wikipedia.org/wiki/Dc_%28computer_program%29

bc is built on dc and uses infix notation.

bc -l supports arbitrary-precision arithmetic, IIRC.

Re: What the hell is Forth? (2019)

#97
As Clutch said, "All the best locations are located on the margins".

It's a shame that the term "Red Pill" has been co-opted by the right-wing crazies like QAnon, because it tarnishes what would otherwise be an excellent term.

Forth, located on the margins between assembly language and high-level languages, is the Red Pill of compilers.

You go from a kilobyte or so of assembly to a fully-working operating system, mostly written in Forth. You've jumped the gap from a system that doesn't even boot to something you can type commands into and get expected results, and write useful code, and do real work on. It fits onto a couple of tracks worth of a floppy disk, and - more importantly - it all fits into your brain in one go.

So, do you take Forth, stay in low-level land, and see how deep the rabbit-hole goes?

Re: What the hell is Forth? (2019)

#98
post #95
post #77

Earlier quoted context omitted.

Reminds me a bit of dc: https://en.wikipedia.org/wiki/Dc_%28computer_program%29

bc is built on dc and uses infix notation. bc -l supports arbitrary-precision arithmetic, IIRC.

`k` in dc sets the fractional digits after the dot.

I am not sure there is a limit but 99 works ...

Re: What the hell is Forth? (2019)

#99
post #84

Earlier quoted context omitted.

I don’t really feel I can judge whether it’s good or not to use generally, but it’s difficult to obtain a similar degree of DSL-ness even on pretty powerful (e.g. Micropython-grade) constrained platforms. Forth, along with Lisp, is one of the original DSL substrates ( Thinking Forth spends like half its pages on preaching EDSLs), and I don’t think it’s really been supplanted in that niche by anything that doesn’t req…

DSL just a library that exports a lot of functions that work together any language that allows naming functions does that?

If you don’t care about syntactic convenience, yes. In practice, a(n idiomatic) Forth “library” can have an API like, for example,

  1000 ,bp) ax mov,
for laying down assembly code in memory (might look a bit unusual, but think “postfix assembler” and it’ll become natural soon enough). If you want this to compile down to byte writes and arithmetic without requiring an assembler library at runtime (DynASM-style), you can do that as well.

Custom control structures[1], object systems, perfect hashing, parser generators, all that fun stuff that’s possible with flexible syntax and arbitrary compile-time code execution, people have done it. You never have to think whether an X-macro is sufficiently ugly yet to warrant a custom preprocessor. (If you want to say “web templating”, you can say “web templating”, except it’s not that pleasant with manual memory management, and most of what I’m thinking about was written in the 80s.)

There’s nothing impossible about this in any language (the absence of a competent C REPL continues to amaze me), but not all languages are good at everything they can technically do, and Forth is good at these.

(Forth is also bad at some things. If you want code that transparently works on floats and doubles, or 32- and 64-bit addresses, on the same system depending on a compile-time setting, it’s going to be painful. Passing abstract types by value is impossible to do elegantly as far as I know. Omitting unnecessary code from the executable, trivial with static libraries and a linker, requires adapting half your implementation and is a serious selling point for commercial Forth systems. And so on.)

[1] I know we’re all alleged adults and are not supposed to get excited about these, but does LuaJIT’s FOLD tree peephole optimizer, for example, qualify as a legitimate custom control structure? (It’s implemented with a combination of macro magic and a custom preprocessor.)

Re: What the hell is Forth? (2019)

#100

A great introduction is the book Starting Forth [0]. It has the most charming illustrations I've ever seen in a text book. [0] https://www.forth.com/starting-forth/

It is a grave error to introduce Forth without noting that it is universally recognized as the First Programming Religion. Lately Lisp and Rust have begun to take on religious overtones, but Forth came first. It is probably also a mistake to introduce it without mentioning that the first two (normally one-character) words defined are pronounced "builds" and "does".

Lately? Lisp has been a religion for decades.
Post reply on HN