previous up next     contents index
Next: Initial Values Up: Creating Classes Previous: Initialization Variables

Instance Variables

Each instance-variable-clause has one of these forms:

 
   (simple-variable-specifier instance-var-declaration  tex2html_wrap_inline8722 ) 
   (directed-variable-specifier superclass-name instance-var-declaration  tex2html_wrap_inline8722 ) 
   (sequence expression  tex2html_wrap_inline8722 ) 

A  sequence clause does not define any instance variables. It only specifies expressions to be evaluated in order at initialization time.

simple-variable-specifiers and directed-variable-specifiers are keyword variable specifiers. They are used in variable declaration clauses to define the properties of instance variables:

Figure 2.1 shows how combinations of the above properties are specified with different variable specifier keyword.

A simple-variable-specifier is one of:  

A directed-variable-specifier is either inherit-from, rename-from, or share-from; these specifiers are refinements of inherit, rename, and share, respectively, where the search path for the inherited instance variable is narrowed to a single superclass.

There can be multiple clauses with the same variable specifier, and different variable specifiers clauses can be declared in any order.

In public, private, and local clauses, each instance-var-declaration has one of the following forms:  

 
   (instance-var-name instance-var-initial-value)
   (instance-var-name)
   instance-var-name 

Each instance-var-name must be an identifier and each instance-var-initial-value is an expression. The scoping rules for the initial value expressions are described below. When an initial value expression is not given, (void) is assumed. An instance variable name can be declared only once within a class definition.

In inherit and inherit-from clauses, each instance-var-declaration is just an identifier that is used as the name of the variable that is inherited.

In rename, share, rename-from, and share-from clauses, each instance-var-declaration has the form:

 
  (instance-var-name inherited-name) 
Both instance-var-name and inherited-name must be an identifier. instance-var-name is the new variable name, and inherited-name is the name of the variable that is inherited.

Inheritance is verified at class-creation time. If an inherited instance variable is not found in the superclass(es), the  exn:object:inherit exception is raised.

   figure486
Figure 2.1: Variable specifier summary


previous up next     contents index
Next: Initial Values Up: Creating Classes Previous: Initialization Variables

PLT