*) instance-form declaration
slot-entry ::= slot-name | (variable-name slot-name)
The macro with-slots establishes a lexical environment for referring to the slots in the instance named by the given slot-names as though they were variables. Within such a context the value of the slot can be specified by using its slot name, as if it were a lexically bound variable. Both setf and setq can be used to set the value of the slot.
(defclass thing () ((x :initarg :x :accessor thing-x) (y :initarg :y :accessor thing-y)))
#<STANDARD-CLASS THING 250020173>
(values (thing-x thing) (thing-y thing))
(with-slots ((x1 x) (y1 y)) thing1 (with-slots ((x2 x) (y2 y)) thing2 (list (list x1 (thing-x thing1) y1 (thing-y thing1) x2 (thing-x thing2) y2 (thing-y thing2)) (setf x1 (+ y1 x2)) (list x1 (thing-x thing1) y1 (thing-y thing1) x2 (thing-x thing2) y2 (thing-y thing2)) (setf (thing-x thing2) (list x1)) (list x1 (thing-x thing1) y1 (thing-y thing1) x2 (thing-x thing2) y2 (thing-y thing2)))))
Changing X from 7 to (9) in #<THING 43147374>.
((1 1 2 2 7 7 8 8) 9 (9 9 2 2 7 7 8 8) (9) (9 9 2 2 (9) (9) 8 8))
The consequences are undefined if any slot-name is not the name of a slot in the instance.
A with-slots expression of the form:
(with-slots (slot-entry1 ... slot-entryn) instance-form form1 ... formn
expands into the equivalent of:
(let ((in instance-form)) (symbol-macrolet (Q1 ... Qn) form1 ... formk))
where Qi, if slot-entryi is a symbol, is:
(slot-entryi () (slot-value in 'slot-entryi))
If slot-entryi is of the form
(variable-namei slot-namei)), then Qi is:
(variable-namei () (slot-value in 'slot-namei))