Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hierarchy of standard-object and standard-class in Common Lisp

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

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.

(taken from http://www.lispworks.com/documentation/HyperSpec/Body/t_std_ob.htm#standard-object) so it is an instance of standard-class

On the other hand standard-class is a subclass of 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?

like image 925
TheEnt Avatar asked Oct 10 '12 08:10

TheEnt


1 Answers

enter image description here

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.

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

The class of the standard-object class object is standard-class.

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

The class of the standard-class class object is standard-class.

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

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>

The class standard-class is itself an object and a class. It is a superclass of all CLOS classes.

like image 144
Rainer Joswig Avatar answered Oct 28 '22 00:10

Rainer Joswig