[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.10 Introspection

Introspection, also known as reflection, is the name given to the ability to obtain information dynamically about GOOPS metaobjects. It is perhaps best illustrated by considering an object oriented language that does not provide any introspection, namely C++.

Nothing in C++ allows a running program to obtain answers to the following types of question:

In C++, answers to such questions can only be determined by looking at the source code, if you have access to it. GOOPS, on the other hand, includes procedures that allow answers to these questions -- or their GOOPS equivalents -- to be obtained dynamically, at run time.

2.10.1 Classes  
2.10.2 Slots  
2.10.3 Instances  
2.10.4 Generic Functions  
2.10.5 Generic Function Methods  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.10.1 Classes

primitive procedure: class-name class
Return the name of class class. This is the value of the class metaobject's name slot.

primitive procedure: class-direct-supers class
Return a list containing the direct superclasses of class. This is the value of the class metaobject's direct-supers slot.

primitive procedure: class-direct-slots class
Return a list containing the slot definitions of the direct slots of class. This is the value of the class metaobject's direct-slots slot.

primitive procedure: class-direct-subclasses class
Return a list containing the direct subclasses of class. This is the value of the class metaobject's direct-subclasses slot.

primitive procedure: class-direct-methods class
Return a list of all the generic function methods that use class as a formal parameter specializer. This is the value of the class metaobject's direct-methods slot.

primitive procedure: class-precedence-list class
Return the class precedence list for class class (see section 4.4.4 Class precedence list). This is the value of the class metaobject's cpl slot.

primitive procedure: class-slots class
Return a list containing the slot definitions for all class's slots, including any slots that are inherited from superclasses. This is the value of the class metaobject's slots slot.

primitive procedure: class-environment class
Return the value of class's environment slot. [ *fixme* I don't know what this value is used for. ]

procedure: class-subclasses class
Return a list of all subclasses of class.

procedure: class-methods class
Return a list of all methods that use class or a subclass of class as one of its formal parameter specializers.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.10.2 Slots

procedure: class-slot-definition class slot-name
Return the slot definition for the slot named slot-name in class class. slot-name should be a symbol.

procedure: slot-definition-name slot-def
Extract and return the slot name from slot-def.

procedure: slot-definition-options slot-def
Extract and return the slot options from slot-def.

procedure: slot-definition-allocation slot-def
Extract and return the slot allocation option from slot-def. This is the value of the #:allocation keyword (see section allocation), or #:instance if the #:allocation keyword is absent.

procedure: slot-definition-getter slot-def
Extract and return the slot getter option from slot-def. This is the value of the #:getter keyword (see section getter), or #f if the #:getter keyword is absent.

procedure: slot-definition-setter slot-def
Extract and return the slot setter option from slot-def. This is the value of the #:setter keyword (see section setter), or #f if the #:setter keyword is absent.

procedure: slot-definition-accessor slot-def
Extract and return the slot accessor option from slot-def. This is the value of the #:accessor keyword (see section accessor), or #f if the #:accessor keyword is absent.

procedure: slot-definition-init-value slot-def
Extract and return the slot init-value option from slot-def. This is the value of the #:init-value keyword (see section init-value), or the unbound value if the #:init-value keyword is absent.

procedure: slot-definition-init-form slot-def
Extract and return the slot init-form option from slot-def. This is the value of the #:init-form keyword (see section init-form), or the unbound value if the #:init-form keyword is absent.

procedure: slot-definition-init-thunk slot-def
Extract and return the slot init-thunk option from slot-def. This is the value of the #:init-thunk keyword (see section init-thunk), or #f if the #:init-thunk keyword is absent.

procedure: slot-definition-init-keyword slot-def
Extract and return the slot init-keyword option from slot-def. This is the value of the #:init-keyword keyword (see section init-keyword), or #f if the #:init-keyword keyword is absent.

procedure: slot-init-function class slot-name
Return the initialization function for the slot named slot-name in class class. slot-name should be a symbol.

The returned initialization function incorporates the effects of the standard #:init-thunk, #:init-form and #:init-value slot options. These initializations can be overridden by the #:init-keyword slot option or by a specialized initialize method, so, in general, the function returned by slot-init-function may be irrelevant. For a fuller discussion, see init-value.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.10.3 Instances

primitive procedure: class-of value
Return the GOOPS class of any Scheme value.

primitive procedure: instance? object
Return #t if object is any GOOPS instance, otherwise #f.

procedure: is-a? object class
Return #t if object is an instance of class or one of its subclasses.

Implementation notes: is-a? uses class-of and class-precedence-list to obtain the class precedence list for object.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.10.4 Generic Functions

primitive procedure: generic-function-name gf
Return the name of generic function gf.

primitive procedure: generic-function-methods gf
Return a list of the methods of generic function gf. This is the value of the gf metaobject's methods slot.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.10.5 Generic Function Methods

primitive procedure: method-generic-function method
Return the generic function that method belongs to. This is the value of the method metaobject's generic-function slot.

primitive procedure: method-specializers method
Return a list of method's formal parameter specializers . This is the value of the method metaobject's specializers slot.

primitive procedure: method-procedure method
Return the procedure that implements method. This is the value of the method metaobject's procedure slot.

generic: method-source
method: method-source (m <method>)
Return an expression that prints to show the definition of method m.

 
(define-generic cube)

(define-method (cube (n <number>))
  (* n n n))

(map method-source (generic-function-methods cube))
=>
((method ((n <number>)) (* n n n)))


[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by Ingo Ruhnke on September, 12 2002 using texi2html