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

后端 未结 2 784
旧时难觅i
旧时难觅i 2021-02-14 09:15

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

相关标签:
2条回答
  • 2021-02-14 09:44

    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.

    0 讨论(0)
  • 2021-02-14 09:47

    To understand this you will need to understand the concept of meta class. The instance of a meta class is a class and the instance of a class is an object, so basically we have 3 level hierarchy.

    standard-class is a meta-class. standard-object is an instance of metaclass standard-class hence it is class. Every other user defined class by default inherits from standard-object class.

    So when you are creating a class, you are basically instantiating standard-class metaclass and this new class is inherited by standard-object class.

    0 讨论(0)
提交回复
热议问题