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

Creating Classes

The built-in class object% has no methods and implements only its own interface, (class->interface object%). All other classes are derived from object%.

The class*/names form creates a new class:

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

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

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

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

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

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_inline100181 ) initialization-variables
     instance-variable-clause
      tex2html_wrap_inline100181 ) 
   tex2html_wrap_inline100269 
  (class*/names (this super-init) superclass-expr (interface-expr  tex2html_wrap_inline100181 ) initialization-variables
     instance-variable-clause
      tex2html_wrap_inline100181 ) 

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

  (class superclass-expr initialization-variables
     instance-variable-clause
      tex2html_wrap_inline100181 ) 
   tex2html_wrap_inline100269 
  (class* superclass-expr () initialization-variables
     instance-variable-clause
      tex2html_wrap_inline100181 ) 

The this-variable and super-init-variable variables (usually this and super-init) 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 (i.e., this) is bound to the object itself, and super-init-variable (i.e., super-init) 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 evaluated when the class*/names expression is evaluated. The result must be a class value (possibly object%), otherwise the exn:object exception is raised. The result of the superclass-expr expression is the new class's superclass.

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 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 exception is raised. The class's superclass must satisfy the implementation requirement of each interface, otherwise the exn:object 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]     [index]
Next: Initialization Variables Up: Classes and Objects Previous: Creating Interfaces

PLT