Chapter 12

The Built-In Functions

Reflective Operations on Types

The following functions return information on types and test type membership. They provide part of the implementation of the type protocol, as described in The Type Protocol beginning on page 49.

instance? [Function]


Tests whether an object is an instance of a type.

Signature:

instance? object type boolean

Arguments:
object

An instance of <object>.

type

An instance of <type>.

Values:
boolean

An instance of <boolean>.

Description:

Returns true if object is a general instance of type.

subtype? [Function]


Tests whether a type is a subtype of another type.

Signature:

subtype? type1 type2 boolean

Arguments:
type1

An instance of <type>.

type2

An instance of <type>.

Values:
boolean

An instance of <boolean>.

Description:

Returns true if type1 is a subtype of type2. Subtype rules are given in The Type Protocol on page 49.

object-class [Function]


Returns the class of an object.

Signature:

object-class object class

Arguments:
object

An instance of <object>.

Values:
class

An instance of <class>.

Description:

Returns the class of which object is a direct instance.

all-superclasses [Function]


Returns the class precedence list of a class.

Signature:

all-superclasses class sequence

Arguments:
class

An instance of <class>.

Values:
sequence

An instance of <sequence>. Each element in the sequence is an instance of <class>.

Description:

Returns the class precedence list of class. This is an ordered sequence ofclass and all its superclasses, as described in Computing the Class Precedence List on page 54.

The result sequence should never be destructively modified. Doing so may cause unpredictable behavior. If class is sealed, an implementation may choose to signal an error of type <sealed-object-error> rather than returning the sequence of all superclasses.

direct-superclasses [Function]


Returns the direct superclasses of a class.

Signature:

direct-superclasses class sequence

Arguments:
class

An instance of <class>.

Values:
sequence

An instance of <sequence>. Each element in the sequence is an instance of <class>.

Description:

Returns the direct superclasses of class in a sequence. These are the classes that were passed as arguments to make or define class when the class was created. The order of the classes in the sequence is the same as the order in which they were passed to define class or make when class was created.

The result sequence should never be destructively modified. Doing so may cause unpredictable behavior. If class is sealed, an implementation may choose to signal an error of type <sealed-object-error> rather than returning the direct superclasses.

direct-subclasses [Function]


Returns the direct subclasses of a class.

Signature:

direct-subclasses class sequence

Arguments:
class

An instance of <class>.

Values:
sequence

An instance of <sequence>. Each element in the sequence is an instance of <class>.

Description:

Returns the direct subclasses of class in a sequence. These are the classes that have class as a direct superclass. The order of the classes in the sequence is not significant.

The result sequence should never be destructively modified. Doing so may cause unpredictable behavior. If class is sealed, an implementation may choose to signal an error of type <sealed-object-error> rather than returning the direct subclasses.