Unique Forth Language Features

Why is Forth an interesting language to study? Why should it be among the languages discussed in a course or textbook on programming languages?

Forth is interesting because it offers a unique combination of language features (e.g., low-level features combined with interactivity and meta-programming). But it also offers features that are unique to Forth (or it least so uncommon that you probably have not studied them elsewhere). This page discusses some of them:

Static Name Binding

What happens when you have a function defined with a name, and define another function with the same name?

In many programming languages, you just get an error. In some programming languages (e.g., Lisp or Postscript), the new definition replaces the old one; all references to the name now reference the new function (dynamic name binding).

In Forth, the old definition continues to exist, and any use of the name that was made before the new definition still refers to the old definition (static name binding). Any newer uses of the name refer to the new definition (i.e., the new definition shadows the old one). [In general, in Forth names are visible from the definition downwards.]

Why is this interesting? Because it is a way to deal with name collisions, without requiring name spaces or similar features (although Forth has such features (called vocabularies or wordlists)).

Consider an application defining a function foo. Somewhat later, the language or an important API is extended with a function foo.

But how do you do forward declarations, e.g., for mutual recursion? And how do you change the behaviour of a word (somewhat like the dynamic name binding of Lisp and Postscript)? There are other mechanisms for that, e.g., deferred words.

Control structures

Coming soon.

Type checking

Coming soon.

Programmer-visible stack

Coming soon.

Explicit run-time compilation

Coming soon.
Anton Ertl