0

I tried to think of a better name for this is but I couldn't. Also every topic on this involves python and I don't know python

I know that the dafult :meta-class is standar-class

And that standard-object is an instance of the standard-class and that every class is an instance of the standard-class and inherits everything from the standard-object but how is this this possible? As in how can standard-object be an object and a superclass both at the same time? How does it work and why?

What I don't understand is how can an instantained class be also a class?

jakHunter
  • 305
  • 3
  • 13
  • What documentation did you look into, where do they fall short ? – Ehvince Aug 01 '18 at 23:02
  • lisp cookbook,lispworks IDE documentation,https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/index.html and google... – jakHunter Aug 01 '18 at 23:04
  • Have you tried to implement a simple interpreter or a class system? If you had you'd know that bootstrapping is just as magical as recursion and somwhat paradoxical. [`standard-object` inherits `standard-object`](http://www.lispworks.com/documentation/lw50/CLHS/Body/t_std_ob.htm#standard-object) – Sylwester Aug 01 '18 at 23:44
  • Possible duplicate of [Hierarchy of standard-object and standard-class in Common Lisp](https://stackoverflow.com/questions/12815105/hierarchy-of-standard-object-and-standard-class-in-common-lisp) – Sylwester Aug 01 '18 at 23:52
  • No let me rephrase my question how can an object be a class? As in how can an instantained class be a class? – jakHunter Aug 02 '18 at 00:03
  • 2
    How can a book which describes how to write a book be a book itself? And why? – Rainer Joswig Aug 02 '18 at 05:55
  • 1
    You'll likely find answers in "the art of the Meta-Object protocol", they show how CLOS is laid out and they explain the bootstrapping problem. – Ehvince Aug 02 '18 at 10:14

2 Answers2

6

One way to think about it is to forget that bootstrapping is a problem and imagine that the object system is “just so” and then it seems natural that:

  • everything is an object
  • every object is an instance of a class
  • every (standard) class is a subclass of standard-object
  • a class is an object
  • every standard class is an object which is an instance of standard-class
  • standard-class is a standard class which is an object which is an instance of standard-class and a subclass of standard-object which is a class which is an object which is an instance of standard-class

I tried and failed to find a good diagram.

Another way to think about this is about bootstrapping. How can you make the above state come to be?

One way is that you can make an object without its class existing:

  1. Decide on the memory layout of objects
  2. Knowing how to lay out an instance of standard-class in memory, allocate an instance that will become the class standard-class
  3. Initialise that instance with the right things. Set its class to be itself. Don’t set any superclasses yet
  4. Do the same to allocate an instance that will become standard-object (and other parts of the hierarchy, ie class, the class of T, generic-function, method, etc)
  5. The class of all of these objects can be set to standard-class
  6. Connect up the class hierarchy relationships
  7. Create generic functions and methods for allocating instances and compiling generic functions and such
  8. Welcome to your new object system
Dan Robertson
  • 4,315
  • 12
  • 17
3

You could ask yourself the question in reverse: why would a class not be an object, in an object-oriented programming language?

What is a class? It's something that contains information about how to create new objects, things like fields, default values, etc… In OOP, the default tool to store data together is an object. So CL's classes are just objects! And because classes are objects themselves, of course they have a class, STANDARD-CLASS (STANDARD-OBJECT is the direct superclass of a class without any other superclasses… cf. Inheritance structure of metaobject classes).

As an exercise, you can try to create your own (very simple) object system and you may discover very fast that having your classes being objects would make your life way easier. Going from there, there is just the slight problem of bootstrapping. :-)

Nowhere man
  • 5,007
  • 3
  • 28
  • 44
  • I think an acceptable answer to “what is a class” could be either “a class exists only at compile time and is converted into specialised function calls and a vtable” or “a class is a special non-runtime thing which can be referred to only by name [and may be introspected by ...]” – Dan Robertson Aug 02 '18 at 19:01
  • You certainly helped a lot I also read https://stackoverflow.com/questions/12815105/hierarchy-of-standard-object-and-standard-class-in-common-lisp and it answered my next question but I have question regarding it. 'standard-class` is basically the root right?Then we have `standard-object` which itself is an instance of `standard-class` and after that we have a separate `standard-class` object-class which is an instance of 'standard-class' and a subclass of `standard-object` right?Took me a lot of time to comprehend this. – jakHunter Aug 03 '18 at 14:36
  • 1
    That's the confusing part, I think, but only because of the bootstrapping and implementation. Your description is correct, but I think the root is `standard-object`, because it's the default superclass of any class without explicit superclasses. Bootstrapping this means: create `standard-object`, then create `standard-class`, then set `standard-object`'s class as `standard-class`, do the same for `standard-class`. When you observe the end result, it's confusing… – Nowhere man Aug 06 '18 at 06:42