FORTH environment for Arduino

Wrote a serial terminal mode for FINF, so it works also without Arduino's Serial Monitor. The provided shell works as you might expect, with common shortcuts such as Ctrl+L to clear the screen, Ctrl+W to delete the last word, etc. It also offers some colored output to help understand better the output. Here's a nice screenshot of a terminal program running on my computer:

(BTW, the terminal code can be easily reused if one needs this kind of thing; it's pretty small, uses only about 500bytes of Flash and 32 bytes of RAM (for the line buffer))

Forth never really caught on... did it.

It did with me.
I wrote a PCB layout program in it on the Mac in the late 80's, I also did a lot of image processing research with it at my University. I also taught it for about 8 years at the University.

About 8 years ago I went to an access control company and a lot of there stuff was written in Forth. I was the only one in the company who could understand it.
A great little language.

I was the only one in the company who could understand it.

Might that say something about forth in itself? Or not. ;D

Yeah, FORTH is pretty obscure, specially by today's standards. But it is simple, short, powerful and -- once you get the hang out of it -- easy to program on.

Of course, it is so different from popular languages that finding examples for it is pretty difficult; and I assume most people that uses Arduinos are learning to program, and this is a problem for them.

Being a programmer for almost 20 years (if typing BASIC programs at age 8 copied from an user's manual count as programming), I can say however that learning non-mainstream languages -- the weird ones, not only on their syntax but on how you're supposed to do things on them -- will greatly improve your problem solving abilities.

FORTH is great as in there is practically no syntax: it's like playing with LEGO, but you often have to create your own bricks. And being interactive, it remembers me the fun it was to program on BASIC on a MSX computer.

FINF is my third FORTH interpreter (it is actually a rewrite of my first FORTH environment), and so far, the one I had the most fun writing. I'll probably try something along the same line later; perhaps a dialect of BASIC, why not?

Anyway. The last couple of days I've sent some bug fixes and new features. FINF is now pretty stable and uses a lot of less memory (didn't know about the PROGMEM trick). Things that were previously not working, such as nested if..then and begin..until blocks are working; they also work while typing the program interactively, which is quite nice. The only thing really needed is a way to store your program; I might use the EEPROM for that, or add support for SD cards in the future.

So, if you've tried FINF the first time I've announced it here, try it again. Be sure to uncomment the "#define TERMINAL 1" line and use a terminal program like GNU screen (Mac / Linux) or Putty (Windows).

Have fun! :slight_smile:

"FORTH never really caught on"!?!?

I guess Adobe NEVER gives any credit to Forth and they should because Postscript IS Forth!
If you ever had an HP programmable calculator, getting into Forth was easy.

Some of my favourite applications are written in Forth, Voyager 1 & 2, the desktop planetarium programme I have running on my Mac (plus!) is a conspicuous example.

Some of my favourite applications are written in Forth, Voyager 1 & 2, the desktop planetarium programme I have running on my Mac (plus!) is a conspicuous example.

I played with Forth on a Sinclair ZX81, back in the day. I recall reading somewhere that Forth was popular with astronomers who used it to control large telescopes. I suppose that enthusiasm has migrated to astronomy software today.

As an artist and not a mathematician, I always thought the phrase 'reverse polish notation' was pretty cool.

Lot's of observatories use Forth.
The Arecibo radio telescope and the VLA radio telescope in New Mexico, this is not surprising, Charles Moore worked at the National Radio Astronomy Observatory (NRAO), he was a freelance programmer working mainly on control and data acquisition, which is where Forth really shines.
The contempt that C programmers show Forth (and just about any other language) is amazing!

The contempt that C programmers show Forth (and just about any other language) is amazing!

Not me. I have equal contempt for all software languages. Solder is the best programming language. :wink:

Lefty

That's pretty impressive... I wonder if you could fit a PHP implementation into an Arduino, that'd take an Arduino webserver to a whole new level.

Hmm.. why not compile an Apache webserver with PHP module (and of course a firewall) :-/
I think it would need some extra RAM memory ;D

Freak me Lefty!
I have this Mars/Lunar lander obsession, my first attempt, age 12, was all relay logic and bulbs!
Then I went to DTL, after the start of the 70's I built a 6800 system, with front panel LED's and switches, you might know the one, from that issue of "Practical Electronics".
Still at it, always will, till I plant that Australian flag on the Moon/Mars, arduino or not.

1 Like

Is it me or does Yoda talk Forth?

'theForce withYou strong is'

Its great to see Forth on an Arduino. Well done! I spent a happy time in the 1980's writing a Forth for a TRS-80.

So many good ideas just fade away.

The contempt that C programmers show Forth (and just about any other language) is amazing!

No, it isn't.

FORTH was an interesting and clever hack that proved a useful solution to a problem that doesn't really exist any more: writing code for von Neumann-architecture machines with limited storage and no/expensive cross-development tools.

But it's definitely a "hack", not a tool for doing serious engineering: it lacks the features (most notably, function prototyping) that make it possible for compilers to catch common programmer errors before they turn into crashes, and make it easy for programmers to write re-usable code.

These days, when many targets have Harvard architectures, and you can use a cheap PC with a free version of GCC/SDCC/whatever to cross-develop for almost anything from a PIC to a supercomputer, FORTH only makes sense for a really tiny set of problems.

The reason for much of the "contempt" is the near-cult (and some would omit the "near" ::)) following it attracted, which succeeded in alienating many people who would've been quite happy to have it as one of several tools in their kit.

Ah, so one could say FORTH is really a good candidate to add to the dustbin of history? ;D

Lefty

I dunno if I'd go that far. Although I would in the case of, say, COBOL. And maybe LISP, if I were in the mood to start a flamewar :sunglasses:

But I definitely wouldn't include it in any CS or engineering curriculum, except as a novelty or thought-provoker. The 17 people on the planet who might actually need to know it someday can pick it up quickly enough on their own.

It's like RPG, or briefcase-sized cellphones: a stop-gap that filled a temporary need, but whose 15 nanoseconds of fame has come and gone.

It is a useful language because it is thought-provoking to students and engineers. Stack-based languages (like PostScript and FORTH) are sometimes a good fit for certain problems. A FORTH interpreter takes up much less space on a deeply-embedded system than a procedural language of equal expressive power (don't ask for proof, it's my opinion :slight_smile:

And it still has some (relatively) modern uses:

Consider the original post: this fellow implemented an INTERACTIVE programming language on a microcontroller with 2K of RAM. Just not possible with C/C++/Java etc. I don't see that need going away.

Plus, FORTH is just plain fun. It's like puzzle-solving, and much more productive than solving Sudokus.

--
The Quick Shield: breakout all 28 pins to quick-connect terminals

SubZer0, you forgot Ruby on Rails.

A nice piece of work !
Before the PC or Mac as we know them existed, I was writing data acquisition programs in figForth for the RCA 1802 processor and I was impressed with the compact power of the language.
Also a user of HP RPN calculators, and there are similarities.
I look forward to trying this out.

Is it supposed to just stop working once you unplug the Lilypad and plug it back in?

Nice one, I've previously had Amforth on an arduino but that needed to overwrite the bootloader etc.

I spent a couple of years using forth to write code for instrumentation used in the water industry for monitoring all the chemicals/compounds in the water as it was being treated. These were 6502 based embedded systems. Also used it for some PID control systems based on PCs too.

Still have a soft spot for it so will have to give this a try. :wink:

Cheers

Andy