[previous] [up] [next]     [contents] [index]
Next: Initialization Variables Up: Classes and Objects Previous: Creating Interfaces

Creating Classes

Classes are created with the class*/names form:

  (class*/names local-names superclass-expr (interface-expr  tex2html_wrap_inline12550 ) initialization-variables
     instance-variable-clause
      tex2html_wrap_inline12550 )

local-names is: (this-variable super-init-variable)

initialization-variables is one of: variable (variable tex2html_wrap_inline12550 variable-with-default tex2html_wrap_inline12550 ) (variable tex2html_wrap_inline12550 variable-with-default tex2html_wrap_inline12550 . variable)

variable-with-default is: (variable default-value-expr)

instance-variable-clause is one of: (sequence expr tex2html_wrap_inline12550 ) (public public-var-declaration tex2html_wrap_inline12550 ) (private private-var-declaration tex2html_wrap_inline12550 ) (inherit inherit-var-declaration tex2html_wrap_inline12550 ) (rename rename-var-declaration tex2html_wrap_inline12550 )

public-var-declaration is one of: ((internal-instance-variable external-instance-variable) instance-var-initial-value-expr) (instance-variable instance-var-initial-value-expr) (instance-variable) instance-variable

private-var-declaration is one of: (internal-instance-variable instance-var-initial-value-expr) (internal-instance-variable) internal-instance-variable

inherit-var-declaration is one of: inherited-variable (internal-instance-variable external-inherited-variable)

rename-var-declaration is: (internal-instance-variable external-inherited-variable)

The class* macro is used to avoid specifying local-names:

  (class* superclass-expr (interface-expr  tex2html_wrap_inline12550 ) initialization-variables
     instance-variable-clause
      tex2html_wrap_inline12550 ) 
   tex2html_wrap_inline12616 
  (class*/names (this super-init) superclass-expr (interface-expr  tex2html_wrap_inline12550 ) initialization-variables
     instance-variable-clause
      tex2html_wrap_inline12550 ) 

The class macro omits both local-names and the interface-exprs:

  (class superclass-expr initialization-variables
     instance-variable-clause
      tex2html_wrap_inline12550 ) 
   tex2html_wrap_inline12616 
  (class* superclass-expr () initialization-variables
     instance-variable-clause
      tex2html_wrap_inline12550 ) 

The this-variable and super-init-variable variables are bound in the rest of the class*/names expression, excluding superclass-expr and the interface-exprs. In instances of the new class, this-variable is bound to the object itself, and super-init-variable is bound to a procedure that must be invoked (once) to initialize instance variable bindings in the superclass (see section 6.4).

The superclass-expr expression is evalauted when the class*/names expression is evaluated. The result must be a class value or null, otherwise the exn:object:class-type exception is raised. The result of the superclass-expr expression is the new class's superclass. If null is provided as the superclass, a special ``null class'' is used as the superclass; when a class is derived from the null class, the null class portion of an object is optionally initialized from the derived class by applying super-init-variable to zero arguments.

The interface-expr expressions are also evaluated when the class*/names expression is evaluated, after superclass-expr is evaluated. The result of each interface-expr must be an interface value, otherwise the exn:object:interface-type exception is raised. The interfaces returned by the interface-exprs are all implemented by the class. For each variable in each interface, the class (or one of its ancestors) must declare a public instance variable with the same name, otherwise the exn:object:implement exception is raised.

The initialization-variables part of a class*/names expression defines the initialization variables as described in section 6.3.1. The instance-variable-clauses define the class's instance variables as described in section 6.3.2.

The result of a class*/names expression is a new class, derived from the specified superclass and implementing the specified interfaces. Instances of the class are created with the make-object procedure as described in section 6.4.




[previous] [up] [next]     [contents] [index]
Next: Initialization Variables Up: Classes and Objects Previous: Creating Interfaces

PLT