Skip to main content

5.2 Metaobjects

Metaobjects

Metaobjects

For each kind of program element there is a corresponding basic metaobject class. These are the classes: class, slot-definition, generic-function, method, and method-combination. A metaobject class is a subclass of exactly one of these classes. The results are undefined if an attempt is made to define a class that is a subclass of more than one basic metaobject class. A metaobject is an instance of a metaobject class.

Each metaobject represents one program element. Associated with each metaobject is the information required to serve its role. This includes information that might be provided directly in a user interface macro such as defclass or defmethod. It also includes information computed indirectly from other metaobjects such as that computed from class inheritance or the full set of methods associated with a generic function.

Much of the information associated with a metaobject is in the form of connections to other metaobjects. This interconnection means that the role of a metaobject is always based on that of other metaobjects. As an introduction to this interconnected structure, this section presents a partial enumeration of the kinds of information associated with each kind of metaobject. More detailed information is presented later.

5.2.1 Classes

Classes

Classes

A class metaobject determines the structure and the default behavior of its instances. The following information is associated with class metaobjects:

  • The name, if there is one, is available as an object.

  • The direct subclasses, direct superclasses and class precedence list are available as lists of class metaobjects.

  • The slots defined directly in the class are available as a list of direct slot definition metaobjects. The slots which are accessible in instances of the class are available as a list of effective slot definition metaobjects.

  • The documentation is available as a string or nil.

  • The methods which use the class as a specializer, and the generic functions associated with those methods are available as lists of method and generic function metaobjects respectively.

5.2.2 Slot Definitions

Slot definitions

Slot definitions

A slot definition metaobject contains information about the definition of a slot. There are two kinds of slot definition metaobjects. A direct slot definition metaobject is used to represent the direct definition of a slot in a class. This corresponds roughly to the slot specifiers found in defclass forms. An effective slot definition metaobject is used to represent information, including inherited information, about a slot which is accessible in instances of a particular class.

Associated with each class metaobject is a list of direct slot definition metaobjects representing the slots defined directly in the class. Also associated with each class metaobject is a list of effective slot definition metaobjects representing the set of slots accessible in instances of that class.

The following information is associated with both direct and effective slot definitions metaobjects:

  • The name, allocation, and type are available as forms that could appear in a defclass form.

  • The initialization form, if there is one, is available as a form that could appear in a defclass form. The initialization form together with its lexical environment is available as a function of no arguments which, when called, returns the result of evaluating the initialization form in its lexical environment. This is called the initfunction of the slot.

  • The slot filling initialization arguments are available as a list of symbols.

  • The documentation is available as a string or nil.

Certain other information is only associated with direct slot definition metaobjects. This information applies only to the direct definition of the slot in the class (it is not inherited).

  • The function names of those generic functions for which there are automatically generated reader and writer methods. This information is available as lists of function names. Any accessors specified in the defclass form are broken down into their equivalent readers and writers in the direct slot definition.

Information, including inherited information, which applies to the definition of a slot in a particular class in which it is accessible is associated only with effective slot definition metaobjects.

  • For certain slots, the location of the slot in instances of the class is available.

5.2.3 Generic Functions

Generic functions

Generic functions

A generic function metaobject contains information about a generic function over and above the information associated with each of the generic function's methods.

  • The name is available as a function name.

  • The methods associated with the generic function are available as a list of method metaobjects.

  • The default class for this generic function's method metaobjects is available as a class metaobject.

  • The lambda list is available as a list.

  • The method combination is available as a method combination metaobject.

  • The documentation is available as a string or nil.

  • The argument precedence order is available as a permutation of those symbols from the lambda list which name the required arguments of the generic function.

  • The declarations are available as a list of declarations.

    There is some ambiguity in Common Lisp about the terms used to identify the various parts of declare special forms. In this document, the term declaration is used to refer to an object that could be an argument to a declare special form. For example, in the special form (declare (special *g1*)), the list (special *g1*) is a declaration.

5.2.4 Methods

Methods

Methods

A method metaobject contains information about a specific method.

  • The qualifiers are available as a list of of non-null atoms.

  • The lambda list is available as a list.

  • The specializers are available as a list of specializer metaobjects.

  • The function is available as a function. This function can be applied to arguments and a list of next methods using apply or funcall.

  • When the method is associated with a generic function, that generic function metaobject is available. A method can be associated with at most one generic function at a time.

  • The documentation is available as a string or nil.

5.2.5 Specializers

Specializers

Specializers

A specializer metaobject represents the specializers of a method. Class metaobjects are themselves specializer metaobjects. A special kind of specializer metaobject is used for eql specializers.

5.2.6 Method Combinations

Method combinations

Method combinations

A method combination metaobject represents the information about the method combination being used by a generic function.

Note

This document does not specify the structure of method combination metaobjects.