
Forth compiler in one literate x86 assembly file - mbrubeck
http://www.annexia.org/forth
======
yason
This is a gem: I've read it before and I read it again.

This is what I long for: simple self-contained bootstrapping systems that can
be eventually used to build anything. These days it seems that all we have is
that "anything" and we'll just glue the pieces together without ever
understading how everything works.

That's what got me started in computers anyway: to understand how _everything_
works.

------
chipsy
A wonderful thing about Forth-style languages is that they are amenable to
many implementation strategies, and if you are looking for a quick-and-dirty
DSL you can usually do it as a Forth.

Something I did recently is a source-to-source compiler as a series of
function calls, e.g.:

1 2 +

may translate to

stack.push(1); stack.push(2); add();

in an Algol-type language. You don't get niceties like a "real" namespace or
interactivity with this approach, but if the function calls are inlined, the
only performance overhead comes from usage of the data stack - making it a
good candidate for "glue code" that doesn't need to be dynamic. It's basically
"Forth-like macro-assembler" at this level.

For things like runtime mutability, interrupt-and-continue behavior, and
interactivity, another strategy is to build an interpreter loop where each
word is a list or array of data containing two types - values and function
calls. Lots of features become possible - even easy - once you do that.

Since I started experimenting with stack languages I've been trending towards
this approach: build a Forth-type API on top of whatever language is best for
the task. Then build the app in the Forth. On the one hand you can say "ah,
but that's not necessary," but on the other, it focuses your energies around
setting up the plumbing well, so that the final solution is small and easy to
extend. And that's always a good outcome.

------
wglb
A book called "Threaded Interpretive Languages" by RG Loeliger is about Forth
(not about multi-threading). The author is sufficiently excited about the
topic that you can envision him falling out of the chair. It also covers the
very basics of how to build Forth.

------
10ren
Does forth qualify for the same category as smalltalk and lisp?

~~~
jacquesm
Forth is an easy-to-bootstrap language that defines several primitive words.

You use the primitives to define other words in order to achieve your desired
effects.

It is a stack-based language.

Forth programs tend to be extremely small, typical usage is in embedded
control applications, though there have been much larger programs written in
Forth. Forth was invented by Chuck Moore, he is still active:

<http://www.colorforth.com/>

It definitely is a language that is worth learning, if only because it will
subtly change your point-of-view.

If you're really interested you might want to read this book:

<http://www.forthfreak.net/thinking-forth.pdf>

------
joeycfan
Awesome. Forth is a great language!

