sbcl 中奇怪的类优先级列表
在 sbcl 中,
*(sb-mop:class-precedence-list (find-class 'cons))
==>(#<BUILT-IN-CLASS CONS> #<BUILT-IN-CLASS LIST> #<BUILT-IN-CLASS SEQUENCE>
#<BUILT-IN-CLASS T>)
cons 继承自 list 而不是相反,这不是很奇怪吗?我在这里缺少什么?
In sbcl,
*(sb-mop:class-precedence-list (find-class 'cons))
==>(#<BUILT-IN-CLASS CONS> #<BUILT-IN-CLASS LIST> #<BUILT-IN-CLASS SEQUENCE>
#<BUILT-IN-CLASS T>)
Isn't it strange that cons inherits from list and not the other way around? What am I missing here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是根据规范。 LIST 可以是 CONS,或符号 NIL (这是 NULL),这意味着这两种类型都是 LIST 的特化,因此它们的等效系统类继承自 LIST。
This is per the specification. A LIST is either a CONS, or a symbol NIL (which is the only object of type NULL), which means that both of those types are specializations of LIST, and hence their equivalent system classes inherit from LIST.
并非所有 conses 都是列表(因为最终的 cdr 可能不是 nil),也不是所有列表都是 conses(nil 不是列表,如前所述)。因此从技术上讲,两个类都不是另一个类的子类。我认为规范是这样写的,因为有人看到了实际用途,但我同意它很令人困惑,而且可能会被误导。
Not all conses are lists (since the ultimate cdr might not be nil), and not all lists are conses (nil is not a list, as mentioned earlier). So technically speaking, neither is of a class that is properly a subclass of the other. I think the spec is written that way because someone saw a practical use, but I agree that it's confusing and it might be misguided.