Is there a way to collect slot definitions readers from the entire inheritance tree?

The general function slot-definition-readers receives an argument, which should be direct-slot-definition . If an object is an instance of a class that inherits from another class, how can I take hold of readers of all the effective slots of the object? Do I need to manually navigate the tree and call slot-definition-readers on the result of class-direct-slots in each superclass, collect the results, or is there another way that I don’t know about?

+2
source share
1 answer

This "community wiki" answer is here to provide an implementation of this function. Subsequently, the destructive operation (NCONC, MAPCAN) is not used, since the implementation can return the internal list without copying it. MAPPEND is imported from alexandria , and MOP operations can be imported from closer-mop .

 (defun all-direct-slots (class) (append (class-direct-slots class) (mappend #'all-direct-slots (class-direct-superclasses class)))) (defun all-slot-readers (class) (mappend #'slot-definition-readers (all-direct-slots class))) 
+2
source

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


All Articles