Previous chapter: #2: First, Second, Third, Last Default (Addition)

Dylan Design Notes: #3: Make Class Specification (Addition)

Dylan Design Notes

#3: Make Class Specification (Addition)

Version 1, March 1993

This design note gives an expanded specification for <class> which enables new classes to be created at runtime, with make.


Replace the specification of <class> on page 91 of the Dylan manual with the following:

<class>        [Abstract Class]
All classes (including <class>) are general instances of <class>. <class> is a subclass of <type>.

In most programs the majority of classes are created with defineclass. 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 variable, or if they want to create new classes at runtime.

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

superclasses:
Specifies the direct superclasses of the class. superclasses: should be a class or a sequence of classes. The default value is <object>. The meaning of the order of the superclasses is the same as in define-class.
debug-name:
Used only for debugging and display purposes. The default is implementation-dependent.
slots:
A sequence of 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. Unless the allocation of the slot is virtual, the setter method for the slot will be added to this generic function. There is no default.
type:
A type. Values stored in the slot are restricted to be of this type. The default value for this option is <object>.
init-value:
Supplies a default initial value for the slot. This option cannot be specified along with init-function. 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 new instances are created. This option cannot be specified along with init-value. 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. There is no default. This option cannot be specified along with required-init-keyword:.
required-init-keyword:
A keyword. This option is like initkeyword:, 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, an error is signaled. There is no default. This option cannot be specified if initkeyword:, init-value:, or init-function: is specified.
allocation:
One of the symbols instance, class, each-subclass, constant, or virtual, or an implementation defined symbol. The meaning of this option is the same as for define-class.

Examples:

(make <class>
      superclasses: <object>
      slots: `((getter: ,point-x
                setter: ,point-x-setter
                init-keyword: ,x:
                init-value: ,0
                type: ,<integer>)
               (getter: ,point-y
                setter: ,point-y-setter
                init-keyword: ,y:
                init-value: ,0
                type: ,<integer>)))

(make <class>
      superclasses: `(,<input-stream> ,<output-stream>)
      slots: `((getter: ,stream-cache
                setter: ,stream-cache-setter
                init-keyword: ,cache:)))
Or, in a different style:
(make <class>
      superclasses: <object>
      slots: (vector (vector getter: point-x
                             setter: point-x-setter
                             init-keyword: x:
                             init-value: 0
                             type: <integer>)
                     (vector getter: point-y
                             setter: point-y-setter
                             init-keyword: y:
                             init-value: 0
                             type: <integer>)))

(make <class>
      superclasses: (vector <input-stream> <output-stream>)
      slots: (vector (vector getter: stream-cache
                             setter: stream-cache-setter
                             init-keyword: cache:)))

Next chapter: #4: No Incremental Class Modifications (Change)