有没有办法从所有继承树中收集插槽定义读取器? [英] Is there a way to gather slot-definition-readers from all the inheritance tree?

查看:102
本文介绍了有没有办法从所有继承树中收集插槽定义读取器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通用函数 slot-definition-readers 获取一个参数,该参数必须为 direct-slot-definition 。如果一个对象是从另一个类继承的一个类的实例,我如何掌握该对象所有有效插槽的读取器?我是否必须遍历树并根据 class-direct-slots 的结果调用 slot-definition-readers

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?

推荐答案

此社区Wiki答案是在此处提供此功能的实现。接下来的内容不使用破坏性操作(NCONC,MAPCAN),因为实现可能会返回内部列表而不复制它。 MAPPEND是从 alexandria 导入的,而MOP操作可以从< a href = http://www.crategus.com/books/closer-mop/ rel = nofollow noreferrer> closer-mop 。

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)))

这篇关于有没有办法从所有继承树中收集插槽定义读取器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆