Node:Metaclass, Next:Class Precedence List, Up:Terminology
A metaclass is the class of an object which represents a GOOPS class. Put more succinctly, a metaclass is a class's class.
Most GOOPS classes have the metaclass <class> and, by default,
any new class that is created using define-class has the
metaclass <class>.
But what does this really mean? To find out, let's look in more detail
at what happens when a new class is created using define-class:
(define-class <my-class> (<object>) . slots)
GOOPS actually expands the define-class form to something like
this
(define <my-class> (class (<object>) . slots))
and thence to
(define <my-class> (make <class> #:supers (list <object>) #:slots slots))
In other words, the value of <my-class> is in fact an instance of
the class <class> with slot values specifying the superclasses
and slot definitions for the class <my-class>. (#:supers
and #:slots are initialization keywords for the dsupers
and dslots slots of the <class> class.)
In order to take advantage of the full power of the GOOPS metaobject
protocol (see MOP Specification), it is sometimes desirable to
create a new class with a metaclass other than the default
<class>. This is done by writing:
(define-class <my-class2> (<object>) slot ... #:metaclass <my-metaclass>)
GOOPS expands this to something like:
(define <my-class2> (make <my-metaclass> #:supers (list <object>) #:slots slots))
In this case, the value of <my-class2> is an instance of the more
specialized class <my-metaclass>. Note that
<my-metaclass> itself must previously have been defined as a
subclass of <class>. For a full discussion of when and how it is
useful to define new metaclasses, see MOP Specification.
Now let's make an instance of <my-class2>:
(define my-object (make <my-class2> ...))
All of the following statements are correct expressions of the
relationships between my-object, <my-class2>,
<my-metaclass> and <class>.
my-object is an instance of the class <my-class2>.
<my-class2> is an instance of the class <my-metaclass>.
<my-metaclass> is an instance of the class <class>.
my-object is <my-class2>.
my-object is <my-metaclass>.
<my-class2> is <my-metaclass>.
<my-class2> is <class>.
<my-metaclass> is <class>.
<my-metaclass> is <class>.
<my-class2> is not a metaclass, since it is does not inherit from
<class>.
<my-metaclass> is a metaclass, since it inherits from
<class>.