views:

689

answers:

6

I am intrigued by stack-based languages like Forth. Are there situations where Forth is the best tool for the job or is it just an intellectual and historical curiosity? What about derivative languages like Factor or Joy? Which of these languages would you recommend learning? And for what purpose (apart from mind expansion)?

+10  A: 

Classic Forths have been well suited to the embedded space because of their overall small size.

But many a higher level systems have been done in Forth, and modern Forths are a far cry from the Leo Brodie days of typing in FIG-Forth assembly listings in to your TRS-80 macro assembler.

Forth is deceptively powerful. It's like Lisp in terms of its abstract power, but it starts with a more primitive toolset and more primitive memory architecture. in Lisp, you really have little exposure to the actual underlying memory model, whereas in typical Forth, the memory model is a primary component.

My favorite stack based is HP RPL (Reverse Polish Lisp) used on their calculators. It really shows you the benefits of a stack based system without have such a bare metal taste that the classic Forths have.

I have not uesd the systems like Factor and such.

You have to respect folks like Chuck Moore (Forth founder and advocate) when you read about his chip design systems etc. that he's written and uses himself. It's interesting to see someone who works on a system with a character resolution akin to a legacy Vic-20 today, but it gets his job done the way he does it, so who's to fault him for that.

At a minimum, like many languages, Forth deserves study. Unfortunately, simple examples fail to really bring out the nature and power of Forth. Just like CAR, CDR, recursion and parentheses drive many away from Lisp thinking that's what it's all about, Forth explorers trying to use the base Forth primitives for higher level applications are quickly frustrated, and, again, don't get the true nature of the system.

But if you have any desire for embedded work, I think it's worth exploring an embedded system with a Forth on it -- it can be a powerful environment.

Will Hartung
It isn't RPL, it's RPN (reverse polish notation).
xcramps
No, it's RPL. I'm referring to the languages on the HP-28S, and the 48/49/50 series. Completely different animal, that just happens to use RPN. http://en.wikipedia.org/wiki/RPL_(programming_language)
Will Hartung
+4  A: 

These days I think it's hard to justify Forth except in situations where hardware resources are very, very limited. But it's definitely worth learning for the mind-expansion factor. I would actually recommend starting by learning PostScript, which you could consider a kind of safe version of Forth where instead of manipulating raw memory you manipulate high-level data types like hash tables (called 'dictionaries' in PostScript), arrays, and so on.

You would also learn a lot by writing an interpreter for either Forth or PostScript. The first edition PostScript without garbage collection is especially easy to write. (I'm talking about the language, not the enormous collection of graphics and rendering operators.)

Having done a fair amount of general-purpose programming in PostScript (I worked on a debugger which used an internal PostScript interpreter for scripting and for evaluating expressions on the target machine), I can say that stack-based programming without names makes my head explode. But it is definitely cool.

As for Forth, I think its day has largely passed. But I am a tremendous fan of Open Boot, which uses Forth in the firmware to get a computer up and running with all its devices. A perfect application for Forth---also well worth learning about.

Norman Ramsey
Delta Forth .NET would make a great learning tool. You can get it at www.dataman.ro/dforthI know because I wrote it :-)
vbocan
+3  A: 

Forth is useful when you need a drop-dead simple compiler for new hardware. Also, Forth is this funny mix of interpreter and compiler, getting somehow the best of both. The downside is that Forth does not play well with cache memory (comments are open if you disagree). By all means do try Forth: it's simple enough for DIY, it expands your mind and is just good fun.

TonJ
+5  A: 

They are mostly a historical curiosity, even though it sees use to this day in unexpected places.

I would not use them for a new project anywhere, unless it had extreme memory constrains, and, mind you, I love Forth. When it was first proposed that FreeBSD use a Forth interpreter for it's loader, I expressed my concern about that -- mostly that no one would ever use it. But since no one could come up with anything else in the space constrains that legacy PC architecture imposed, Forth it was (specifically, FICL).

The problems faced by the stack languages, though, are the following:

  • Foremost, it hides the data being passed around, making it difficult to understand what is being done.
  • Second, it is difficult to refactor, as there are no automated checks that the code has been corrected to account for changes in the number or type of the parameters.
  • Third, the learning curve is high, because of the reverse polish notation.
  • Fourth, there's little outside support, be it community or library.

Forth itself has further problems, but which can be -- and have been -- addressed by other stack languages. It has, though, some endearing qualities:

  • You can grow the language to whatever you like -- to the point of fixing all of the problems above (with the exception of community support); you'd end up with something no one else in the world understands, though, or copying something that exists.
  • The language and compiler are such that it's not difficult to have complete understanding of how everything in it works.
  • It DOES work in very limited environments, though the particular limits we are talking about are very rare nowadays.
  • It teaches decomposition like nothing else. Either that, or you won't be able to read anything you write.
Daniel
A: 

Forth is vary fast to write in (once you are comfortable writing in it), it executes rather quickly, and it compiles down very small. One drawback is that unless the programmers have enough discipline to document their code well enough, they won't be able to read each others' code.

We used it in the 80s to create demo software for new computers, and tutorials to teach new users how to use the computer. This required a lot of graphics and sounds and whatever special effects we could pull in each machine. (By "graphics", I mean we had artists drawing pictures and then we would put them together into animations, adding whatever special effects we needed).

--H

Hamachisn't
A: 

It still crops up in robotics and spaceship systems. Pololu (a robotic microcontroller company) makes a servo control module that runs a form of forth internally, and though I can't site references, I've heard that a number of existing space probes use Forth for at least some of their internal systems.

hdan