Chapter 11

The Built-In Classes

Types

Types are used to categorize objects. Figure 11-1 shows the built-in classes of types and some of their characteristics.

Figure 11-1 The Type Classes

class singleton class class class type class object Type Class Hierarchy
S – Sealed P – Primary C – Concrete I – Instantiable
O – Open F – Free A – Abstract U – Uninstantiable

General Types

<type> [Sealed Abstract Class]


The class of all types, including classes and other types.

Superclasses:

<object>

Init-keywords:

None.

Description:

The class of all types. All types (including <type> and <class>) are instances of <type>.

Operations:

The class <type> provides the following operations:

Table 11-4 Functions on <type>

Function

Description

Page

instance?

Tests whether an object is an instance of a type.

343

subtype?

Tests whether a type is a subtype of another type.

343

type-union

Returns the union of two or more types.

266

Table 11-5 Generic Functions on <type>

Function

Description

Page

make

Returns a general instance of its first argument.

258

Classes

<class> [Sealed Instantiable Class]


The class of all Dylan classes.

Superclasses:

<type>

Init-keywords:

The class <class> supports the following init-keywords:

superclasses:

An instance of <class> or <sequence> specifying the direct superclasses of the class. If it is a sequence, the elements of the sequence must be instances of <class>. The default value is <object>. The meaning of the order of the superclasses is the same as in define class.

abstract?:

An instance of <boolean> specifying whether the class is abstract or concrete. The default value is #f.

slots:

An instance of <sequence> containing slot specs, where each slot-spec is a sequence of keyword/value pairs.

The following keywords and corresponding values are accepted by all implementations. Implementations may also define additional keywords and values for use within slot specs.

getter:

A generic function of one argument. Unless the allocation of the slot is virtual, the getter method for the slot will be added to this generic function. This option is required.

setter:

A generic function of two arguments, or #f indicating no setter. Unless the allocation of the slot is virtual, the setter method for the slot will be added to this generic function. The default value is #f.

type:

A type. Values stored in the slot are restricted to be of this type. The default value is <object>.

deferred-type:


A function of no arguments, which returns a type, and is called once to compute the type of the slot, within the call to make that constructs the first instance of that class. For a given slot spec, either type: or deferred-type: may be specified, but not both.

init-value:

A default initial value for the slot. This option cannot be specified along with init-function: or required-init-keyword: and it cannot be specified for a virtual slot. There is no default.

init-function:


A function of no arguments. This function will be called to generate an initial value for the slot when a new instances is created. This option cannot be specified along with init-value: or required-init-keyword: and it cannot be specified for a virtual slot. There is no default.

init-keyword:


A keyword. This option permits an initial value for the slot to be passed to make, as a keyword argument using this keyword. This option cannot be specified for a virtual slot. There is no default. This option cannot be specified along with required-init-keyword:.

required-init-keyword:


A keyword. This option is like init-keyword:, except it indicates an init-keyword that must be provided when the class is instantiated. If make is called on the class and a required init-keyword is not provided in the defaulted initialization arguments, an error is signaled. There is no default. This option cannot be specified if init-keyword:, init-value:, or init-function: is specified, or for a virtual slot.

allocation:

One of the keywords instance:, class:, each-subclass:, or virtual:, or an implementation defined keyword. The meaning of this option is the same as adding the corresponding adjective to a define class form.

Description:

The class of all classes. All classes (including <class>) are general instances of <class>.

In most programs the majority of classes are created with define class. However, there is nothing to prevent programmers from creating classes by calling make, for example, if they want to create a class without storing it in a module binding, or if they want to create new classes at runtime.

If make is used to create a new class and creating the new class would violate any restrictions specified by sealing directives, then an error of type <sealed-object-error> is signaled.

Operations:

The class <class> provides the following operations:

Table 11-6 Functions on <class>

Function

Description

Page

all-superclasses

Returns the class precedence list a class.

344

direct-superclasses

Returns the direct superclasses of a class.

345

direct-subclasses

Returns the direct subclasses of a class.

345

limited

Returns a limited subtype of a class.

263

Table 11-7 Methods on <class>

Function

Description

Page

make

Returns a general instance of its first argument.

259

Singletons

<singleton> [Sealed Instantiable Class]


The class of types that indicate a single object.

Superclasses:

<type>

Init-keywords:

The class <singleton> supports the following init-keyword:

object:

An instance of <object>. The object that the singleton indicates. There is no default for this argument. If it is not supplied, an error will be signaled.

Description:

The class of singletons.

If a singleton for the specified object already exists, implementations may return it rather than allocating a new singleton.

Operations:

None.