Live data from Hacker News

Forth: The Hacker’s Language

hackaday.com

51–60 of 111 posts

Re: Forth: The Hacker’s Language

#51

There is a decent amount of Forth publications out there, but nothing that really takes you from A->Z in building your own Forth based off of Assembly or C. JonesForth helped me conceptually understand parts of Forth, but there is a lot missing there for me to be able to start from scratch. I would pay $ for a real book in the vein of "Land of Lisp" that shows you how to build a Forth compiler/editor and how to exten…

You might find R. G. Loeliger's book "Threaded Interpretive Languages: Their Design and Implementation" [1] interesting. Here's a review [2]. The comments on that review list some online resources that might also be useful.

It's long out of print, but used copies are cheap, and scans are readily findable on the net.

I wrote a comment a while back outlining how to do a FORTH-like language from scratch by starting with a simple calculator and expanding it, writing in C with optional assembly optimizations. This was aimed at people who have less knowledge of FORTH-like systems than you do, I think, but if you are curious here it is [3].

[1] https://www.amazon.com/Threaded-Interpretive-Languages-Desig...

[2] http://www.retroprogramming.com/2010/03/threaded-interpretiv...

[3] https://news.ycombinator.com/item?id=13082825

Re: Forth: The Hacker’s Language

#52

I'm a embedded software dev and write code all day in C. Sure enough forth comes up in conversations once in a while as does other ideas like Python, JS, Lua etc.. Of all the alternatives to C, Forth is the only one which groks hardware. This is particularly important for embedded development. Any realistic alternative to C must understand interrupts, memory mapped registers etc.. Forth is the only one in which this…

> Any realistic alternative to C must understand interrupts, memory mapped registers etc..

In what way does C understand interrupts?

Re: Forth: The Hacker’s Language

#53
post #52

I'm a embedded software dev and write code all day in C. Sure enough forth comes up in conversations once in a while as does other ideas like Python, JS, Lua etc.. Of all the alternatives to C, Forth is the only one which groks hardware. This is particularly important for embedded development. Any realistic alternative to C must understand interrupts, memory mapped registers etc.. Forth is the only one in which this…

> Any realistic alternative to C must understand interrupts, memory mapped registers etc.. In what way does C understand interrupts?

Borland C used to, and I believe OpenWatcom still does. Haven't seen any other one that did for a long time.

Re: Forth: The Hacker’s Language

#54
I really, really wanted to like Forth. I love learning new languages and different paradigms from those I know already. The fact that Forth was really tiny and yet very powerful and could do meta-programming in a Lisp-like way (though I hadn't yet learned Lisp at the time to fully appreciate what this meant) was also very attractive.

Unfortunately, learning Forth was a real let down. Forth turned out to be way too much of a write-only language for me, with lots of convoluted, hard to understand code. The Forth community preaches simplicity and using short, clear, well documented words (functions). But the reality, at least in most of the open source Forth code I've seen was the opposite, with long, convoluted, poorly documented words being the rule rather than the exception. I've been told that commercial Forth code is a lot better in these respects, but I haven't verified that.

I've also heard even Forth fans tell me that the whole point of Forth is to write yourself something more pleasant than Forth to work in as quickly as possible. Since I don't have an interest or need to write programming languages myself, I'd just rather start with something more pleasant from the beginning, and skip the painful stage of having to work with Forth.

In very resource constrained environments where your only alternative to assembly is Forth, Forth might be the best choice. But since I don't do most of my programming in such environments, I really don't see the point of using Forth at all.

Finally, after learning Forth, I went on to learn Lisp and then Scheme, and fell in love. Those (especially Scheme) really were super clear and easy to both write and read, and felt far more powerful and not at all painful. I felt far more productive in them, and would now far rather use a tiny Scheme or even Lisp on a resource constrained system, if at all possible.

Re: Forth: The Hacker’s Language

#55
post #18

Earlier quoted context omitted.

> Any realistic alternative to C must understand interrupts, memory mapped registers etc.. Forth is the only one in which this is possible. Every other example I've seen always uses C for "low-level" access or a libraries. Forth is a great little language, and a perfect example of how to to do a surprising amount with very little. For more complicated embedded work, however, I've been deeply impressed with Philipp Op…

Yeah, but Rust is much more complex than Forth, and really hates baremetal: you can do baremetal in Rust, but it's idiomatic to minimize contact. That works really well in some cases: OS work, for example. But if you're working in a raw microconroller, you're going to be touching metal constantly, and you won't want anything you don't use slowing you down. In short, Rust is great, but it doesn't beat Forth in Forth's…

Not to mention that Rust is not interactive and doesn't allow for dynamic, incremental development. Forth brings the rapid, extremely tight feedback loop one sees in Lisp or Smalltalk to hardware.

Comparing it to Rust is missing this point entirely. Finally, let's not forget that Forth has been empirically validated multiple times in this domain (e.g. NASA has used Forth on board satellites and spacecraft).

Rust is entirely unproven in the hardware/microcontroller space (some would say in general), so I tend to view posts like ekidd's ("for more complicated embedded work") as projecting/wishful thinking.

Re: Forth: The Hacker’s Language

#56
post #4

I came to Forth-like languages via PostScript, which has the advantage of a huge built-in graphics library. It very naturally introduces concepts like higher order operations, code as data and data as code.

I really lament that PDF and the victory of Motif meant the end of PostScript for most purposes. Sadly I was a bit too young for NeWS, and there seems no emulation available anywhere. Ghostscript itself isn't exactly tooled for actual programming...

Back in the 90s the most popular train route web site in Germany used to send you a PS file for printing on Linux (they did something more native for Windows). And that was basically a serious of quite easy to understand line drawing and text positioning instructions.

And I think it was jwz who had some cassette cover sheets where you put in the song and artist data by editing the PostScript file itself.

Re: Forth: The Hacker’s Language

#57
post #44

One of the most complex games Starflight of the 80th's is written in Forth. I had a lot of fun decompiling it. https://github.com/s-macke/starflight-reverse It turns out to be very portable because the assembler code is only about 1000-2000 lines. The rest is implemented in Forth itself. They use indirect threading to produce very dense code. They kept even most of the debugging symbols inside the code and kept the f…

Neat. Rather akin to Infocom's Z-machine (or to the newer Glulx), although less task-specific.

It is similar, but the compiled code here is not fully architecture independent like for the Z-machine. Each word in Forth is compiled to a function pointer. So the Forth code vary for another architecture or when you recompile. But thanks to debugging symbols this is easily reverse engineered and you can easily figure out what is "+" or "-" for example.

Re: Forth: The Hacker’s Language

#58
post #4

I came to Forth-like languages via PostScript, which has the advantage of a huge built-in graphics library. It very naturally introduces concepts like higher order operations, code as data and data as code.

Can you reccomend any books on PS?

Not the OP, but "Thinking in Postscript" is often recommended and available freely.

http://w3-o.cs.hm.edu/~ruckert/compiler/ThinkingInPostScript...

Re: Forth: The Hacker’s Language

#59
post #27

Earlier quoted context omitted.

There was no Internet and knowledge was shared via magazines and computer clubs. Forth was quite popular in Europe thanks to Jupiter Ace and ZX Spectrum extensions. https://en.wikipedia.org/wiki/Jupiter_Ace http://www.worldofspectrum.org/infoseekid.cgi?id=0008717

That's true. And APL and its children is still quite popular in finance. By the way, I found a rather neat page about building a Jupiter ACE: http://searle.hostei.com/grant/JupiterAce/JupiterAce.html

Mentioning APL in this context makes me picture an 8 bit home computer with an APL interpreter. I mean, the C64 had all kinds of weird symbols on its keyboard, too. And the magazines would save quite some pages for their source code listing compared to BASIC...

Re: Forth: The Hacker’s Language

#60
Just saw recently that the classic FORTH tutorial is available online:

Starting FORTH — Online Edition:

https://www.forth.com/starting-forth/

I had read it and played around with FORTH on a microcomputer some years ago. Fun language.

Thinking FORTH, a more advanced book, also by Leo Brodie, is also linked to from the above URL.

Post reply on HN