Working in the National Look-out post of Radio astronomy of the United States at the beginning of the 70s, Charles Moore was charged to schedule the first minicomputers 16 bits (typify IBM 360) for the purchase of scientific data and the maintenance of equipment.
The high-level languages of time as the FORTRAN (not to confuse with the object of this paragraph) was too heavy for the execution of real-time software packages. Machine language was, as for him, indigestible enough to venture to realize always more complex programs.
And so Charles MOORE had the idea to create a revolutionary language the instructions of bases of which corresponded to a single line of code in machine language.
This allowed not only to write programs in high-level language with almost the performances of machine language but besides reducing at most size memory which was extremely weak at the time.
Charles MOORE wanted to record his language under the name of FOURTH for language of fourth generation but the computer which he used authorizing only names of 5 letters, he called it: FORTH.
Well to understand and to use at most performances inferred by the language FORTH, it is important to master inverted Polish notation used also with calculators made by Hewlett-Packard. The transmission of parameters makes essentially by a last in-first out stack. This notion is what allowed Charles Moore to pull the maximum of performances of its language because it is necessary to know that any processor deserving of this name possesses memory manipulation instructions under shape of stack of this type.
Besides the classic stack of return from subroutines administered intrinsically with most of the processors, the idea to use the same instructions for parameters transfers drove to create a data stack of which some basic instructions are the following ones:
Operations such as comparisons or additions will directly consume the numbers situated at the top of the stack:
The most control basic structure is the set formed with IF, ELSE AND THEN. IF tests the number at the top of the stack by pulling it. If it is different from 0, instructions placed between IF and ELSE are executed then program connects following the word THEN. If it is zero, program connects directly in instructions being following the word ELSE. Several structures of this type can be obviously been linked.
In FORTH, all the instructions can be programs and mutually. They are introduced into the memory according to their compilation. Put in by some instructions which manipulate the return stack as the structures of control for example, all the instructions can be interpreted at any time what gives considerable opportunities of settling for developers. Useless to write another main program and to redo a compilation to see if it is subroutine which works badly . It is enough to launch his execution with adequate parameters.
Instructions or programs or subroutines are inserted into the memory with pointers' system which connect them among them to allow the interpreter (or in the compiler according to the mode of functioning) to find them. Search begins by leaving of the last compiled instruction and by raising until the first which is often DUP. If instruction does not exist, the interpreter / compiler looks if it is a number and piles it at the top of the stack in interpretation mode or compiles it in the instruction in compilation mode. To create an instruction, one uses 2 instructions (except those that describe the sequence to be executed):
Finally, not to be too exhaustive in this presentation, know that FORTH language allows to write recurse procedures what makes a really very evolved language of it. Here is the example of factorial calculation program of an integer appealing to this notion of recursion:
: FACTORIELLE DUP 1 > IF DUP 1 - FACTORIELLE * THEN ;