gpt4 book ai didi

lisp - Common Lisp 中标准对象和标准类的层次结构

转载 作者:太空宇宙 更新时间:2023-11-03 18:34:09 25 4
gpt4 key购买 nike

我正在学习 Common Lisp(使用 Lispworks)并且我现在正在尝试进入类系统。有一个名为 standard-object 的类,它被定义为

The class standard-object is an instance of standard-class and is a superclass of every class that is an instance of standard-class except itself.

(取自http://www.lispworks.com/documentation/HyperSpec/Body/t_std_ob.htm#standard-object)所以它是 standard-class

的实例

另一方面,standard-classstandard-object 的子类

>(subtypep 'standard-class 'standard-object)
=>T, T

标准对象如何既是标准类的父类(super class)又是它的实例?如果我们将标准类定义为子类型,我们应该在其父类(super class)型(例如标准对象)的定义之后定义它,那么父类(super class)怎么会成为实例呢?还是我的逻辑错了?

最佳答案

enter image description here

CLOS 是一个对象系统,其中 CLOS 概念本身是一等对象。类本身是元类的实例。这涉及到一些循环。

有一个实例standard-object。它是 standard-class 的一个实例。它本身就是一个类。所有标准 CLOS 对象都将其作为父类(super class)。还有其他类型的对象,例如结构。所以 standard-object 是所有典型 CLOS 对象的父类(super class)。

standard-class 是它自己的实例。它是所有类对象的类。由于 standard-object 也是一个类,因此类 standard-object 的实例是类 standard-class 的实例。由于所有标准类也是 CLOS 对象,standard-class 继承自 standard-object

CL-USER 22 > (class-of (find-class 'standard-object))
#<STANDARD-CLASS STANDARD-CLASS 40F016A063>

standard-object类对象的类是standard-class

CL-USER 23 > (class-of (find-class 'standard-class))
#<STANDARD-CLASS STANDARD-CLASS 40F016A063>

standard-class类对象的类是standard-class

CL-USER 24 > (find-class 'standard-object)
#<STANDARD-CLASS STANDARD-OBJECT 40F017732B>

standard-object 类本身就是一个对象和一个类。它是所有 CLOS 对象的父类(super class)。

CL-USER 25 > (find-class 'standard-class)
#<STANDARD-CLASS STANDARD-CLASS 40F016A063>

standard-class 类本身就是一个对象和一个类。它是所有 CLOS 类的父类(super class)。

关于lisp - Common Lisp 中标准对象和标准类的层次结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12815105/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com