[comp.lang.forth] Fifth vs Forth

ir230@sdcc6.ucsd.edu (john wavrik) (12/12/90)

                            FORTH vs FIFTH

Somewhere along the way I acquired a copy of FIFTH and a recent 
posting asking about the differences of Forth and Fifth led me to pull 
it out and try a few things. The first thing I tried exposed a 
difference -- there is a difference in the dictionary structure. Fifth 
does not handle redefinition in the way Forth does (in my copy it 
produces an endless loop). 

The Forth dictionary is a linked list (the fact that it is threaded 
in some versions of Forth only has the effect of preventing us from 
changing links to influence search order). A noticeable and useful 
feature of this data structure is the ability to redefine words. In 
Forth self-reference deliberately does not produce recursion -- but 
instead it produces redefinition. 

Some of the systems that I (and others) write are modular. Certain 
capabilities are coded (and loaded) separately. A complete working 
system is produced by loading desired components. A working system 
may be thought of as a leaf of a tree -- certain alternate components 
have been selected for loading at each stage. A consequence of this 
method for building systems is that capabilities may exist in a 
partial system that must be extended (in potentially several different 
ways) when higher level components are loaded. 

A simple example is the word RESET. I use RESET generically -- it 
means to restore the entire system (whatever it happens to be at the 
time) to a known initial state. RESET may relink linked lists, set 
system variables to initial values, etc. Each module of the system has 
a definition:

   : RESET   RESET  <...initialization for current module....> ; 

Thus, as the system is extended, the meaning of RESET is appropriately 
extended IN A TRANSPARENT WAY. I never need to know, when coding, what 
is involved in RESETting the earlier parts of the system -- and I 
never need to know explicitly what has been loaded.  Whatever it is, 
RESET resets it!

More complicated examples are generated by the compounding of data 
types. Mathematics abounds in compound data types which are obtained 
from simpler data types -- we may have matrices whose entries are 
polynomials with integer coefficients; or polynomials whose 
coefficients are matrices with rational entries; or matrices whose 
entries are matrices with integer entries; or .....  These can be 
handled in Forth by a modular construction in which redefinition is 
used to link the modules. 

Dealing with modular construction of this sort is by no means trivial 
in most languages. The fact that it can be done so well in Forth is a 
tribute to the linked list structure of the Forth dictionary and the 
barrier against recursive self-reference. 

                                                  John J Wavrik 
             jjwavrik@ucsd.edu                    Dept of Math  C-012 
                                                  Univ of Calif - San Diego 
                                                  La Jolla, CA  92093