Common Lisp中的标准对象和标准类的层次结构 [英] Hierarchy of standard-object and standard-class in Common Lisp
问题描述
我正在研究Common Lisp(与Lispworks),并且现在正在尝试进入课堂系统.有一个名为 standard-object 的类,它定义为
I'm studying Common Lisp (with Lispworks) and I'm trying to get into class system right now. There is a class called standard-object and it is defined as
类 standard-object 是 standard-class 的一个实例,并且是每个作为 standard-class 的实例的类的超类. >本身除外.
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/正文/t_std_ob.htm#standard-object ) 因此它是标准类
另一方面, standard-class 是 standard-object
>(subtypep 'standard-class 'standard-object)
=>T, T
标准对象如何成为标准类的超类并同时成为其实例?如果我们将标准类定义为子类型,则应在其超类定义后 定义它(例如,标准对象),那么,超类怎么可能成为实例呢?还是我的逻辑是错误的?
How can the standard-object be a superclass for the standard-class and be its instance at the same time? If we define standard-class as a subtype, we should define it after defenition of its supertype (e.g. standard-object), so how can it be, that the superclass becomes the instance? Or my logic is just wrong?
推荐答案
CLOS是一个对象系统,其中CLOS概念本身是一流的对象.类本身是元类的实例.涉及到一些循环性.
CLOS is an object system, where CLOS concepts itself are first-class objects. Classes themselves are instances - of a meta class. There is some circularity involved.
有一个实例standard-object
.这是standard-class
的实例.它本身就是一个类.所有标准CLOS对象都将其作为超类.还有其他类型的对象,例如结构.因此,standard-object
作为所有典型CLOS对象的超类都存在.
There is an instance standard-object
. It's an instance of standard-class
. It is a class itself. All standard CLOS objects will have it as a superclass. There are other types of objects, for example structures. So standard-object
is there as a superclass for all typical CLOS objects.
standard-class
是其自身的实例.它是所有类对象的类.因为standard-object
也是一个类,所以类standard-object
的实例是类standard-class
的实例.由于所有标准类也是CLOS对象,因此standard-class
继承自standard-object
.
standard-class
is in instance of itself. It is the class of all class objects. Since standard-object
is also a class, the instance for the class standard-object
is an instance of the class standard-class
. Since all standard classes are also CLOS objects, standard-class
inherits from 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对象的超类.
The class standard-object
is itself an object and a class. It is a superclass of all CLOS objects.
CL-USER 25 > (find-class 'standard-class)
#<STANDARD-CLASS STANDARD-CLASS 40F016A063>
类standard-class
本身是一个对象和一个类.它是所有CLOS类的超类.
The class standard-class
is itself an object and a class. It is a superclass of all CLOS classes.
这篇关于Common Lisp中的标准对象和标准类的层次结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!