Is there a way to gather slot-definition-readers from all the inheritance tree?

只愿长相守 提交于 2020-01-11 10:23:11

问题


The generic function slot-definition-readers gets an argument that must be a direct-slot-definition. If an object is an instance of a class that inherits from another class how can I get hold of the readers of all the effective-slots of the object? Do I manually have to traverse the tree and call slot-definition-readers on the result of class-direct-slots in each superclass, gathering the results, or is there another way that I am not aware of?


回答1:


This "community wiki" answer is here to provide an implementation of this feature. What follows uses no destructive operation (NCONC, MAPCAN) since an implementation might return an 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)))


来源:https://stackoverflow.com/questions/38452350/is-there-a-way-to-gather-slot-definition-readers-from-all-the-inheritance-tree

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!