
Forth: The Hacker’s Language (2017) - lordgrenville
https://hackaday.com/2017/01/27/forth-the-hackers-language/
======
lunchables
Anytime I hear about Forth I will forever be reminded of this:

[http://www.atarimania.com/documents/FORTH-on-the-Atari-
Learn...](http://www.atarimania.com/documents/FORTH-on-the-Atari-Learning-by-
Using.pdf)

~~~
RandomInteger4
I will forever be reminded of this:

[http://vignette2.wikia.nocookie.net/technicpack/images/9/96/...](http://vignette2.wikia.nocookie.net/technicpack/images/9/96/Example_Redpower_Computer_Setup.png/revision/latest?cb=20120907061532)

~~~
cptnapalm
Is that a Minecraft PDP-8?

~~~
NikkiA
It'll be a redpower computer, programmed in forth:

[https://technicpack.fandom.com/wiki/Basic_Forth_Programming](https://technicpack.fandom.com/wiki/Basic_Forth_Programming)

ComputerCraft (programmed in lua usually) is more common these days.

~~~
RandomInteger4
Computercraft or that newer one, openComputers, which has the memory blocks
and such similar to redpower2.

------
anadem
The first paid programming contract I got, back in the late 70s, was writing a
records management system for a water company .. we wrote the Forth
interpreter too, for a 6502 CPU, to get low-level access to hardware such as
water level sensors. A major obstacle was getting British Telecoms' permission
to send data over the POTS line, but it all worked well for years. I _love_
Forth.

~~~
6thaccount2
I really wish there was a modern book on implementing a useful Forth for x86
or Raspberry PI out of C. Not just a pamphlet either, but a thick book
covering how to choose between all the different threading options...etc.

~~~
microtherion
I don't know about "modern", but you could go the traditional route and
bootstrap it from Assembler (You'll find that you only have to implement a
tiny number of primitives until you can start implementing the rest in Forth
itself).

Chapter 9 of Leo Brodie's "Starting Forth" is the text that kicked off my
implementation in the early 80s (and undoubtedly countless others):
[https://www.forth.com/starting-forth/9-forth-
execution/](https://www.forth.com/starting-forth/9-forth-execution/)

~~~
6thaccount2
Does Brodie's book cover implementation though? I can code in Forth a bit
already, but want to know more about implementing in a low level language.

~~~
bdowling
> want to know more about implementing in a low level language.

You might check out Jonesforth [0], which is an extensively-documented Forth
implemented in x86 assembly language. If you read the single source file top
to bottom, you'll get a good understanding of how it is implemented. There are
also ports to x86-64, ARM, and other machines.

If you're looking for something in C, you might check out Ficl. [1]

[0]
[https://github.com/nornagon/jonesforth/blob/master/jonesfort...](https://github.com/nornagon/jonesforth/blob/master/jonesforth.S)
[1] [http://ficl.sourceforge.net](http://ficl.sourceforge.net)

~~~
6thaccount2
I always forget about Jonesforth. Glad to see it's on GitHub now!

~~~
bdowling
> Glad to see it's on GitHub now!

Ah, that github link is not the official repository. The following link
appears to be the official repo:

[http://git.annexia.org/?p=jonesforth.git](http://git.annexia.org/?p=jonesforth.git)

------
johnisgood
Must read: "Thinking Forth: A Language and Philosophy for Solving Problems" by
Leo Brodie ([https://www.dnd.utwente.nl/~tim/colorforth/Leo-
Brodie/thinki...](https://www.dnd.utwente.nl/~tim/colorforth/Leo-
Brodie/thinking-forth.pdf))

Most of the principles described in the book can be applied to any programming
languages, but the book itself uses Forth. Give it a try!

If you want to learn Forth, this might be the book you need:
[https://www.forth.com/starting-forth/](https://www.forth.com/starting-forth/)
([https://1scyem2bunjw1ghzsf1cjwwn-wpengine.netdna-
ssl.com/wp-...](https://1scyem2bunjw1ghzsf1cjwwn-wpengine.netdna-ssl.com/wp-
content/uploads/2018/01/Starting-FORTH.pdf))

Old HN discussion:
[https://news.ycombinator.com/item?id=13505285](https://news.ycombinator.com/item?id=13505285)

\---

I would also recommend checking out Factor
([http://factorcode.org/](http://factorcode.org/), created by Slava Pestov).

More details on the programming language:

\-
[https://concatenative.org/wiki/view/Factor](https://concatenative.org/wiki/view/Factor)

\-
[https://concatenative.org/wiki/view/Factor/FAQ/Why%3F](https://concatenative.org/wiki/view/Factor/FAQ/Why%3F)

\-
[https://concatenative.org/wiki/view/Factor/Learning](https://concatenative.org/wiki/view/Factor/Learning)

Old HN discussion:
[https://news.ycombinator.com/item?id=9008472](https://news.ycombinator.com/item?id=9008472)

\---

Happy hacking!

------
virtualritz
I recall Real3D, a DCC app originating from the Amiga and ported to Windows NT
in the 90's. It allowed plug-ins to be written in RPL (Real Programming
Language) a Forth dialect.

I wrote a 5k line RenderMan RIB exporter for this app in RPL.

I remember how hard this seemed when I started but how natural working in a
RPN language felt after only a few hours. It was almost as if the stack had
become an extension of my brain.

Trivia: Real3D was eventually rewritten from scratch and is now called
Realsoft 3D. Afaik it doesn't support RPL/Forth any more.

~~~
immigrantsheep
That was my first ever 3D app. And Imagine. Before moving to lightwave, still
on the Amiga a couple of years later.

------
carapace
Don't miss "Thinking FORTH" (PDF) linked from the caption of a drawing:
[https://www.forth.com/forth-books/](https://www.forth.com/forth-books/)

------
scandox
> redefine 2 as a function that will return seven, and forever after your math
> won’t work. (But why would you?)

I often think of myself in the past as a completely different person who seems
to be capable of many surprising actions.

~~~
astrobe_
Actually it is not uncommon to see 0, 1 and -1 defined as built-in primitives.
The benefit is that in some interpretation schemes (bytecode, DTC) it is
either faster or smaller, sometimes both. It also allows to _' 0_ ("tick"
zero, that is get the address of the next word, which in this case is some
primitive _zero_ ) to pass it as a "function pointer" to another
function/definition/word.

------
yesenadam
I just downloaded 4tH with macports, anyone have experience or tips with that?
Seems very cool.

"4tH is a very small Forth compiler that can create bytecode, C-embeddable
bytecode, standalone executables, but also works fine as a scripting language.
It supports over 85% of the ANS Forth CORE wordset and features conditional
compilation, pipes, files, assertions, forward declarations, recursion,
include files, etc."

Home page:
[https://thebeez.home.xs4all.nl/4tH/](https://thebeez.home.xs4all.nl/4tH/)

Also..anyone tried or programmed in colorForth? Sounds extremely colourful!

"colorForth uses different colors in its source code (replacing some of the
punctuation in standard Forth) to determine how different words are treated."

[https://en.wikipedia.org/wiki/ColorForth](https://en.wikipedia.org/wiki/ColorForth)

------
sriku
A bit of a shameless plug - I did a short course for programmers at my company
whose purpose was to introduce people to programming paradigms by constructing
a language semantics first in JS. The language is forth-like for simplicity
and I called it "slang".

[https://github.com/srikumarks/nospoon](https://github.com/srikumarks/nospoon)

Would like to hear if anyone thinks it is worth continuing to elaborate on.

------
fpgaminer
Oddly enough I discovered Forth when I was developing a game a few years ago.

The idea for the game was that you pilot a space ship, but your only interface
was a C64-like clone. You'd have to write programs to navigate, make jumps,
and explore the galaxy. Connect to space stations using a modem, and dial into
their local BBS for buying and selling goods.

So I built a 6502 emulator and emulated hardware for all the subsystems
(display, disk, engines, modem, etc). It really was a legit emulated system
... just that some of the addressable hardware was a space ship :P

I started out using a modified KERNAL ROM with BASIC, but ran into problems.
In the first iterations of the game all the subsystems were a bit too
realistic. For sensors you'd have to manually move the sensor beam around and
read out results constantly. For the engines you have to manually adjust the
engine thrust and read back velocity information. Same with the jump mechanic.

I figured making the subsystems realistic, as if they were real hardware that
you had to write firmware for, would be interesting. But coding the "firmware"
in BASIC was a nightmare, and so slow. The jump subsystem was especially
problematic, because the velocity was so high. The program would point your
ship at a space station in the local system, engage jump drives, and then
constantly monitor distance to the station and try to disengage once you got
close enough. But because of the high speeds and the need for large integers
to represent the distances, the program just couldn't PEEK and react fast
enough. I could never get it accurate enough to drop out of jump close to the
station. So you'd spend 10 minutes crawling over there with your sub-
lightspeed drives the jump.

And on top of those speed issues, BASIC was too much of a PITA when you had to
do a lot of hardware manipulation and processing of large numbers (like the
vast distances of space...).

So after hacking on that for awhile I looked for a better alternative. That's
when I stumbled into Forth. There's an actively developed Forth for C64
([https://github.com/jkotlinski/durexforth](https://github.com/jkotlinski/durexforth))
which even included a Vi implementation. So I could get a nicer, faster
language and an editor in one package!

A bit of hacking later, and it really was a massive improvement. It was
especially nice having VI.

I ended up ditching a lot of the hardcore realism in the subsystems. Even with
DurexForth, which was significantly faster and handled the math better, it was
still problematic coding what should be fundamental programs in this game. And
it certainly wasn't fun (if a game like this could ever be considered fun).

But the journey gave me a lot of exposure to Forth, and it is such an
interesting language. I definitely recommend playing with Forth, at least for
a weekend, just for fun and to expand your mind a little.

P.S. As for the game, it's collecting dust. One of these days I'd like to dust
it off and get back to it; I find the idea of it terribly seductive. It's like
a new genre: 6502-Punk :P But I'm half tempted to drop back to BASIC, since
Forth is such a foreign experience. I'd probably continue simplifying the
subsystems, add a floating point co-processor, and mod BASIC to use large
hardware backed floats, just to make everything easy.

------
spdegabrielle
Doesn’t Forth suffer from the Lisp curse ?

~~~
tluyben2
Yes. I like the language because it is so simple to implement; when I want to
do live discovery on something new (hardware or software), I load up a forth
and start playing. If fits everywhere and it is easy to discover stuff without
having to jump through hoops.

------
elboza
there is also a powerful implementation for nodejs
[https://www.npmjs.com/package/force-
lang](https://www.npmjs.com/package/force-lang)

~~~
ASalazarMX
Why is it a "powerful" implementation instead of just an implementation?

> It is called Force because of its assonance of Forth and since the Force is
> the main power of the Jedi the files have .j (or .jedi) extension. So Force
> is the Jedi programmers language !

Oh.

------
wry_discontent
I don't get it. Who's using this, and for what?

~~~
kjs3
It's a good option for embedded, especially low resource embedded,
applications. Provides a nicer set of abstractions than assembler and let's
you create basically a tuned DSL for your problem. That said, development
doesn't scale particularly well, multi-member dev teams are hard, and
maintenance of someone else's code can be, shall we say, challenging.

I always wondered how Sun and Apple addressed this, as they used forth in the
form of OpenBootPROM as a boot environment on various platforms. Very, very
nice.

~~~
AdieuToLogic
I always wondered how they scaled their firmware teams myself. Really
impressive stuff though:

[https://www.openfirmware.org/Open_Firmware](https://www.openfirmware.org/Open_Firmware)

[https://www.openfirmware.org/Forth/FCode](https://www.openfirmware.org/Forth/FCode)

~~~
kjs3
Another interesting example for those looking for a Forth rabbit hole is the
Cannon Cat ([http://www.canoncat.org/](http://www.canoncat.org/)) from Jef
Raskin's (of Mac fame) team.

On the (much) lower end was the Jupiter Ace ([https://jupiter-
ace.com/jupiterace/](https://jupiter-ace.com/jupiterace/)). The Ace is a fun
what-might-have-been where Forth beat BASIC for the '80s PC soul. There were
commercial Forths for other PCs of the time (Apple II, Atari 800, TI99), but I
guess because they were extra cost, they didn't become that popular.

------
otabdeveloper4
> The hacker's language

No, that would be C. (In both senses of the word 'hacker'.)

