Next: , Previous: , Up: Symbols   [Contents][Index]

5.6.6 Property Lists

Each symbol has a property list (or plist), this is a structure which associates an arbitrary Lisp object with a key (usually a symbol). The keys in a plist may not have any duplications (so that each property is only defined once).

The concept of a property list is very similar to an association list (see Association Lists) but there are two main differences:

  1. Structure; each element of an alist represents one key/association pair. In a plist each pair of elements represents an association: the first is the key, the second the property. For example, where an alist may be,
    ((one . 1) (two . 2) (three . 3))

    a property list would be,

    (one 1 two 2 three 3)
  2. Plists have their own set of functions to modify the list. This is done destructively, altering the property list (since the plist is stored in only one location, the symbol, this is quite safe).
Function: get symbol property

This function searches the property list of the symbol symbol for a property equal to property. If such a property is found it is returned, otherwise false is returned.

(get 'if 'lisp-indent)
    ⇒ 2

(get 'set 'lisp-indent)
    ⇒ ()
Function: put symbol property new-value

put sets the value of the property property to new-value in the property list of the symbol symbol. If there is an existing value for this property (using equal to compare keys) it is overwritten. The value returned is new-value.

(put 'foo 'prop 200)
    ⇒ 200
Function: symbol-plist symbol

Returns the property list of the symbol symbol.

(symbol-plist 'if)
    ⇒ (lisp-indent 2)
Function: setplist symbol plist

This function sets the property list of the symbol symbol to plist.

(setplist 'foo '(zombie yes))
    ⇒ (zombie yes)

Next: , Previous: , Up: Symbols   [Contents][Index]