Common Lisp: How to check if a slot is connected? (CLOS)

Say we have a slot without: initform

(defclass foo () ((x :reader x :initarg x))) 

How to check if slot x of an instance of foo is tied?

There is a way to do this with a MOP, which I find very ugly. Is there an easier way?

I would prefer:

 (defclass foo () ((x :reader x :initarg x :initform nil))) 

and just check if it is zero or not - in this case x can never be nil (ambiguous).

+4
source share
1 answer

find all characters with SLOT in the CL package:

 CL-USER 1 > (apropos "SLOT" "CL") SLOT-MISSING (defined) UNBOUND-SLOT-INSTANCE (defined) SLOT-VALUE (defined) SLOT-BOUNDP (defined) SLOT-EXISTS-P (defined) WITH-SLOTS (defined macro) SLOT-MAKUNBOUND (defined) UNBOUND-SLOT MAKE-LOAD-FORM-SAVING-SLOTS (defined) SLOT-UNBOUND (defined) 

I would suggest that SLOT-BOUNDP does what you want. Looking at Common Lisp HyperSpec, we can verify this:

+11
source

Source: https://habr.com/ru/post/1399302/


All Articles