5.3 Creating Objects
The make-object procedure creates a new object with by-position initialization arguments, the new form creates a new object with by-name initialization arguments, and the instantiate form creates a new object with both by-position and by-name initialization arguments.
All fields in the newly created object are initially bound to the special #<undefined> value (see Void and Undefined). Initialization variables with default value expressions (and no provided value) are also initialized to #<undefined>. After argument values are assigned to initialization variables, expressions in field clauses, init-field clauses with no provided argument, init clauses with no provided argument, private field definitions, and other expressions are evaluated. Those expressions are evaluated as they appear in the class expression, from left to right.
Sometime during the evaluation of the expressions, superclass-declared initializations must be executed once by using the super-make-object procedure, super-new form, or super-instantiate form.
By-name initialization arguments to a class that have no matching initialization variable are implicitly added as by-name arguments to a super-make-object, super-new, or super-instantiate invocation, after the explicit arguments. If multiple initialization arguments are provided for the same name, the first (if any) is used, and the unused arguments are propagated to the superclass. (Note that converted by-position arguments are always placed before explicit by-name arguments.) The initialization procedure for the object% class accepts zero initialization arguments; if it receives any by-name initialization arguments, then exn:fail:object exception is raised.
If the end of initialization is reached for any class in the hierarchy without invoking the superclass’s initialization, the exn:fail:object exception is raised. Also, if superclass initialization is invoked more than once, the exn:fail:object exception is raised.
Fields inherited from a superclass are not initialized until the superclass’s initialization procedure is invoked. In contrast, all methods are available for an object as soon as the object is created; the overriding of methods is not affect by initialization (unlike objects in C++).
(make-object class init-v ...) → object? |
class : class? |
init-v : any/c |
(new class-expr (id by-name-expr) ...) |
(instantiate class-expr (by-pos-expr ...) (id by-name-expr) ...) |
(super-instantiate (by-pos-expr ...) (id by-expr ...) ...) |
Invokes superclass initialization with the specified by-position and by-name arguments. See Creating Objects for more information.
(super-new (id by-name-expr ...) ...) |