(rontolisp) docs
← Macros

with-slots

(with-slots (slot-or-pair...) instance body...)

Binds the slot names of a CLOS-subset instance (defclass / define-condition) as symbol-macro-style places for the body: each entry is a slot name, or a (var slot) pair binding var to slot slot. The instance form is evaluated once. Reads see the slots, and setf/push/incf of a bound name writes back to the slot. An inner binding of the name, a nested with-slots of the same slot included, stops it in its scope, as for symbol-macrolet.

Lite: code GENERATED at run time inside the body (e.g. a macrolet template mentioning a slot name) resolves the name through a fallback binding holding the slot's value at entry -- reads work, but a write from such generated code updates that local copy only.

macroexpand-1 answers CL's expansion, a let of the instance around a symbol-macrolet of the names, so a code walker that expands the body after it keeps them in scope.

with-slots only BINDS -- it never reads a slot on entry -- so a body that merely assigns a slot declared without an :initform works, and the fallback binding above holds nil for such a slot. A read the body really performs still signals unbound-slot.