People have often dreamed of programming computers with a natural language
such as English, but the problem of ambiguity remains insuperable.
Forth, like English, is made up of words separated by spaces but it has a
simpler syntax, made possible by the use of a stack.
Unlike other computer languages there are no lists of parameters enclosed
in brackets. Instead of saying 2+2 or +(2,2) we say 2 2 +. Each word
stands on its own. When we say + the computer does not have to wait
to discover what to add, because it is already there, on the stack.
The noun always comes before the verb that acts on it, as is natural
in English whenever urgent commands are issued.
Programming consists of defining new words, using those the computer
already knows. Forth encourages short definitions which can be tested as
soon as they are written. In that way, when a bug appears, you can be
pretty sure it is in the last word you defined, not somewhere in several
pages of code.
Since the entire language structure is embodied in words, the application
programmer can "extend" Forth to add new operators, program constructs,
or data types at will. The Forth "core" includes operators for integers,
addresses, characters, and boolean values; string and floating-point
operators may be optionally added.
Forth has been called "a language for writing languages" - by defining new
words you create the language that best describes the problem in hand.
Indeed, most of a Forth system is itself written in Forth, and the essential
core is so small and simple that it is perfectly possible for an amateur
to write their own Forth. There are however many implementations available.
Sponsored by MikeT
Last modified at: