sbcl 中奇怪的类优先级列表

发布于 2024-11-09 23:46:52 字数 266 浏览 0 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我也只是我 2024-11-16 23:46:52

这是根据规范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.

秋意浓 2024-11-16 23:46:52

并非所有 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文