Forth is one of those interesting languages that has a cult-like following. If you’ve never looked into it, its strength is that it is dead simple to put on most CPUs, yet it is very powerful and productive. There are two main principles that make this possible. First, parsing is easy because any sequence of non-space characters makes up a legitimate Forth word. So while words like “double” and “solve” are legal Forth words, so is “#$#” if that’s what you want to define.
The other thing that makes Forth both simple and powerful is that it is stack-based. If you are used to a slide rule or an HP calculator, it is very natural to think of “5+2*3” as “5 2 3 * +” but it is also very simple for the computer to interpret.
[Zeroflag] created PunyForth–a Forth-like language for the ESP8266. You can also run PunyForth for cross development purposes on Linux (including the Raspberry Pi). The system isn’t quite proper Forth, but it is close enough that if you know Forth, you’ll have no trouble.
According to the project’s documentation, here’s a list of differences between Forth and PunyForth:
- Punyforth is case sensitive
- Strings are null-terminated
- Strings are created and printed differently
- Parsing words are ended with a colon character by convention
- Defining a word in terms of itself results in recursion by default (use the override word to alter this behavior)
- Curly brackets denote quotations instead of locals
None of that is anything that makes it very strange if you already know Forth. If you don’t know Forth, then none of this will strike you as unusal, anyway.
The system provides a TCP shell. It also supports exception handling, cooperative multitasking, socket and GPIO APIs.
If you are into Forth, you’ll like this. If you aren’t, you still might like the expereince of developing interactively directly on the hardware. Just remember, the key is to define words (subroutines) that allow you to write easy-to-read (and write and debug) high-level programs.