2.10 Properties, Flags

Another important concept of LISP is the ability to assign properties and flags to each symbol. A property is a symbol (a “name”) together with a value. Both, property name and property value are completely free. Properties are set by the function put and read by the function get.

      put(’hugo,’evaluator,’compute_hugo);  
        . . .  
      get(’hugo,’evaluator) => compute_hugo  
      get(’otto,’evaluator) => nil

A property-value pair remains assigned for a symbol until the value is replaced by a different value or until the property is removed by remprop.

A flag is similar to a property, but it represents only the values “yes” or “no” (= flag is present or absent). The functions for setting and testing flags are flag and flagp, remflag for removal.

As most other LISP programs, REDUCE makes extensive use of properties. E.g. the algebraic properties of an operator are encoded in that way. So the symbol plus has among others the REDUCE properties prtch = + (the print character), infix = 267 (the precedence among the infix operators), simpfn = simpplus (the name of the routine responsible for its simplification) and the flags symmetric, realvalued, nary and some more. These allow a data driven programming model which has been used in the LISP world for decades already: if the simplifier operates on an expression, it asks the leading operator for its simplification function; if there is one (and there will be one for all operators), this function is invoked to do the job.

There are various fields where this type of programming is used inside REDUCE, e.g. the complete domain arithmetic has been implemented in that way: any non-integer domain element is encoded as a list with a leading symbol (the domain mode) which contains all knowledge about arithmetic, conversion, printing etc. for this domain as properties and flags.

If your REDUCE system is based on PSL, you can inspect a property list by calling the function prop which has one argument (the symbol to be inspected) and which returns the properties and flags as list. E.g.

    a := mat((1,2),(3,4));  
    prop ’a;  
    prop ’mat;  
    prop ’matrix;