
Forth vs Lisp - gnosis
http://www.c2.com/cgi/wiki?ForthVsLisp
======
RodgerTheGreat
The comparison to Lisp is most accurate in the sense that learning Forth will
change the way you code- it's wonderful to get a completely different
perspective every now and then.

Never tried Forth? Do yourself a favor and start now with jsforth[1] or
install the "gforth" package. Read _Starting Forth_ [2] for a gentle
introduction to the language and _Thinking Forth_ [3] for an in-depth
examination of the idioms and patterns of Forth programming.

[1] <http://forthfreak.net/jsforth80x25.html>

[2] <http://home.iae.nl/users/mhx/sf.html>

[3] <http://thinking-forth.sourceforge.net/>

------
tygorius
Interesting that in the previous Lisp vs Python discussion [1], the original
article noted that (f x) could mean a lot of things, to which at least one
comment retorted that in real code you always have a context, so there really
isn't any ambiguity. Yet in this discussion there's a Lisper arguing that with
A B C in Forth, you have no idea how many items have been left on the stack.
(I presume this is based on a lack of experience, as Canonical Forth style
suggests each word starts with a comment detailing beginning and ending stack
states.) I find myself wondering, A B C would be surrounded by contextual
code, so in real code the meaning would be clear, no?

I think that sociologically Lisp and Forth users are more alike than not, but
the camps rarely seem talk to each other. It's clear from Forth's history that
it has a secure niche in 8- & 16-bit microcontroller applications. I have no
idea if there is such a thing as a Lisp application niche these days.

[1] <http://news.ycombinator.com/item?id=2242594>

Edit: link and typo

------
cduan
PostScript is another stack-based language based on Forth, but with
specialized graphics commands. It also has the delightful property that many
printers can interpret it. I always wished I had known this while taking my
intro CS courses, so that I could have submitted my problem sets as PostScript
files, to be computed by the printer.

~~~
protomyth
I came to Forth after programming in Postscript and still have a fondness for
stack-based languages. I actually think Postscript was the better language of
the two, it seemed to easier somehow.

// In the early 90's I got a job that needed me to create a lot of reports /
graphs out of a foxbase database. I had a postscript printer and a copy of
Turbo C 2.0 (don't forget to download the floating point patch). Gotta love
hand coding Postscript templates. I was loving life when I finally got a
openstep box.

~~~
RodgerTheGreat
Factor's heterogenous stack (complex objects rather than integers) definitely
reminds me more of PostScript than Forth, and I agree it can make programming
much more straightforward. I also liked how PS handles flow control- while
Forth uses rather traditional looking left-to-right reading constructs:

    
    
      3 5 > if ." greater" else ." less" then
    

PostScript goes with operators like "if" and "ifelse" that consume code
literals from the stack (enclosed in curly braces):

    
    
      3 5 gt { (greater) print } { (less) print } ifelse
    

It's a little heavier weight, but very flexible and it feels like a natural
way to handle postfix conditionals.

------
lkozma
A different account of Forth, which convinced me at least to stay away from
it: [http://www.yosefk.com/blog/my-history-with-forth-stack-
machi...](http://www.yosefk.com/blog/my-history-with-forth-stack-
machines.html)

~~~
dwc
I read that a while back also. I'm afraid you got the wrong impression. Forth
is another tool, to be used when appropriate. It seems best used when you can
adopt the whole Forth worldview, which goes far beyond the typical mental
shifts required to switch between, say, C and Lisp.

As I understand it, Forth shines when you look at the entirety of a project
and are prepared to find the leanest, most elegant solution to the exact
problem, not limited to writing programs for commodity hardware. Forth people
are kind of like Motie Engineers[1].

[1] <http://en.wikipedia.org/wiki/The_Mote_in_God%27s_Eye#Moties>

------
kabdib
It's an interesting language, and surprisingly easy to implement. Everyone
should try their hand at it.

------
digitailor
People have implemented Forth in Lisp:

<http://formlis.wordpress.com/2010/06/30/forth-in-lisp/>

Anybody know of vice versa?

~~~
celoyd
Here’s a sketch of how you could write a toy lisp in forth:

Let’s use “(* 4 (+ 5 6))” as an example input string.

1\. Drop ( and ): “* 4 + 5 6”.

2\. Tokenize on whitespace and reverse the tokens: 6 5 + 4 *

3\. This is forth. Execute it.

There’s at least one class of bug here (that “(- a b)” != “b a -”)), but it
shows a sense in which they’re very similar languages. From 40,000 feet, lisp
could be called a syntax hack to add variadic functions to a backwards dialect
of forth.

To put it another way, forth really is trivially tree-structured just like
lisp, but the trees are implicit in the number of arguments the functions
take. This allows tricks that depend on the AST being easy to work with, just
like lisp macros.

~~~
rsaarelm
You can also do `(+ 1 2 3)` in Lisp, but `3 2 1 +` doesn't evaluate to 6 in
Forth.

~~~
michaelcampbell
That's lower than the 40000 feet the person to whom you were replying was
flying; in his post he mentions specifically variadic functions.

------
Stormbringer
Hooray! A pissing match that boils down to whether stacks are better than
lists! // _rolls eyes_

Was _very_ tempted to say "... match _between two dead languages_ that ..."

But then somebody would nitpick, and they'd get 500 karma, and I'd get -20 and
I would burn with the fury of a thousand suns... or if not that then at least
the mild annoyance of a social worker watching a hobo be set on fire but not
being arsed to do anything about it.

/sarcasm

