[previous] [up] [next]     [contents] [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 o s), where o is an object and s is a symbol, extracts the value of the instance variable of o with the external name s.

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:ivar exception is raised.

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

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

The send macro is useful for invoking methods:

  (send o name arg  tex2html_wrap_inline12550 ) 
   tex2html_wrap_inline12616 
  ((ivar o name) arg  tex2html_wrap_inline12550 ) 




PLT