[previous] [up] [next]     [index]
Next: Generic Procedures Up: Classes and Objects Previous: Creating Objects

Instance Variable Access

In expressions within a class definition (e.g., within an instance variable's initial value expression), the internal variables declared in the class are all part of the environment. Thus, an internal instance variable is used directly to get a value, and set! is used to set an instance variable's value. However, set! can only be used on definition variables (public and private), not reference variables (inherit and rename).[footnote]

Instance variable values are accessed from outside an object with the ivar/proc procedure: (ivar/proc object symbol) extracts the value of the instance variable of object with the external name symbol.

Hidden instance variables (declared with private or rename) can never be accessed using ivar/proc, and internal names for exposed variables are not recognized by ivar/proc. If a specified instance variable cannot be found by ivar/proc, the exn:object exception is raised.

Instead of using the ivar/proc procedure directly, instance variable values are usually obtained with the ivar form:

  (ivar o name) 
  (ivar/proc o (quote name)) 

The send macro is useful for invoking methods:

  (send o name arg  tex2html_wrap_inline100181 ) 
  ((ivar o name) arg  tex2html_wrap_inline100181 )