Go to the first, previous, next, last section, table of contents.


Understanding Symbols

The Muq symbol is borrowed directly from Lisp, which has been refining the concept for half a century now. Lisp symbols are vaguely equivalent to the "external identifiers" of languages like C in that they provide global (to the current package, at least) names for important functions and datastructures.

The only datastructure components in very early Lisps were symbols and cons cells: Cons cells provided a way to build up complex structures and associations, while symbols provided stopping points in this graph, points of reference which could be given names and values. These early symbols were datastructures in memory containing a single slot, which pointed to a property list of keyValue pairs:

    Symbol            Property List of Cons Cells
   +-------+          +---------------+
   |   o --------->   |   o   |  o--------->  key0
   +-------+          +---|-----------+
                          v
                      +---------------+
                      |   o   |  o--------->  val0
                      +---|-----------+
                          v
                      +---------------+
                      |   o   |  o--------->  val1
                      +---|-----------+
                          v
                      +---------------+
                      |       |  o--------->  val1
                      +---------------+

Typical keyvals found in the property list were the print-name of the symbol, the value of the symbol considered as a variable (if any), and the value of the symbol considered as a function (if any).

Lisp very early acquired a reputation as a very slow language which consumed inordinate amounts of memory, and implementation techniques such as the above were part of the reason.

It didn't take too long to conclude that the Lisp interpreter would both run faster and take less memory if the most frequently used property list values were stored directly in reserved slots in the symbol instead of on the property list, leading to a datastructure looking like:

    Symbol            
   +-------+          
   |   o --------->   Print name of symbol
   +-------+          
   |   o --------->   Value as a variable
   +-------+          
   |   o --------->   Value as a function
   +-------+          
   |   o --------->   Package owning symbol
   +-------+          +---------------+
   |   o --------->   |   o   |  o--------->  key0
   +-------+          +---|-----------+
                          v
                      +---------------+
                      |   o   |  o--------->  val0
                      +---|-----------+
                          v
                      +---------------+
                      |   o   |  o--------->  val1
                      +---|-----------+
                          v
                      +---------------+
                      |       |  o--------->  val1
                      +---------------+

(With the most frequently used values moved into the symbol itself, the property list is no longer as heavily used as it once was, but it is still available. See section `symbolPlist' in Muf Reference, See section `setSymbolPlist' in Muf Reference.)

So, a Muq symbol is essentially a vector with slots reserved to hold its name, value as a variable, value as a function, home package, and property list. (Modern compiled Lisps may actually implement symbols in a variety of different ways, including techniques essentially indistinguishable from those used by conventional C compilers, but Muq sticks with the traditional implementation technique.) Functions are available to read and write most of these slots individually when you need to: See section `symbol functions' in Muf Reference.

A Muq package is really little more than a Muq object all of whose public and hidden keyval pairs "happen" to have symbols for their value half. In particular, you may iterate over all the symbols in a package using the normal object iterators:

( List all variables in the current package: )
: lv { -> }
    @$s.package foreachHidden key val do{
        val symbolValue -> val
        val if key , "\t" , val , "\n" , fi
    }
;


Go to the first, previous, next, last section, table of contents.