symbol-plist
symbol-plist Accessor
Syntax:
symbol-plist symbol → plist
(setf (symbol-plist symbol**)** new-plist**)**
Arguments and Values:
symbol—a symbol.
plist, new-plist—a property list.
Description:
Accesses the property list of symbol.
Examples:
(setq sym (gensym)) → #:G9723
(symbol-plist sym) → ()
(setf (get sym ’prop1) ’val1) → VAL1
(symbol-plist sym) → (PROP1 VAL1)
(setf (get sym ’prop2) ’val2) → VAL2
(symbol-plist sym) → (PROP2 VAL2 PROP1 VAL1)
(setf (symbol-plist sym) (list ’prop3 ’val3)) → (PROP3 VAL3)
(symbol-plist sym) → (PROP3 VAL3)
Exceptional Situations:
Should signal an error of type type-error if symbol is not a symbol.
See Also:
get, remprop
Notes:
The use of setf should be avoided, since a symbol’s property list is a global resource that can contain information established and depended upon by unrelated programs in the same Lisp image.
symbol-valueExpanded Reference: symbol-plist
Basic usage
symbol-plist returns the property list associated with a symbol. A fresh symbol has an empty property list.
(let ((sym (gensym)))
(symbol-plist sym))
=> NIL
Viewing properties after adding them with get/setf
Properties are typically added with (setf (get ...)). symbol-plist reveals the underlying list structure.
(let ((sym (make-symbol "EXAMPLE")))
(setf (get sym 'color) 'red)
(setf (get sym 'size) 42)
(symbol-plist sym))
;; => (SIZE 42 COLOR RED) (order may vary)
Directly setting the property list
You can replace the entire property list with setf, though this is generally discouraged since property lists are a shared global resource.
(let ((sym (make-symbol "DEMO")))
(setf (get sym 'a) 1)
(setf (get sym 'b) 2)
(format nil "Before: ~S" (symbol-plist sym))
(setf (symbol-plist sym) '(x 10 y 20))
(values (get sym 'x) (get sym 'y) (get sym 'a)))
=> 10
=> 20
=> NIL
Property list structure
The property list is a flat list of alternating indicators and values.
(let ((sym (make-symbol "DATA")))
(setf (get sym 'name) "Alice")
(setf (get sym 'age) 30)
(let ((plist (symbol-plist sym)))
(values (length plist)
(evenp (length plist)))))
=> 4
=> T
Empty property list for standard symbols
Most standard symbols do not have property list entries by default (though implementations may add some).
;; Check the type of what symbol-plist returns
(listp (symbol-plist (make-symbol "FRESH")))
=> T