previous up next     contents index
Next: Utilities Up: Instance Variable Access Previous: Instance Variable Access

Generic Procedures

A generic procedure takes an object and extracts an instance variable value from the object. Each generic procedure works on instances of a single class (or instances of derived classes) and always extracts a value for the same instance variable.

The make-generic   form creates a generic procedure:

 
  (make-generic class name) 

The expression class is evaluated and must be a class value. The expression name is not evaluated; it must be an identifier that is the name of an instance variable defined in the class (or one of its superclasses). If the instance variable is not found, the  exn:object:class-ivar exception is raised.

The uq-make-generic   form is like make-generic, but the naming argument is evaluated:

 
  (uq-make-generic class name-expr) 

A generic procedure extracts the (potentially) overridden value of an instance. This is different than ivar, which always extracts the non-overridden value of an instance variable with respect to some class. Thus, ((make-generic class name) obj) is not necessarily equivalent to (ivar obj name): these expressions can give different results if obj is an instance of a class derived from class in which name is locally redeclared (with a local or inherit declaration).

Generic procedures are provided mainly for efficiency. To extract the value of the same instance variable from multiple objects, it is usually more efficient to create a single generic procedure and use it each time than to use ivar each time.

If a generic procedure is applied to an object from the wrong class, the  exn:obj:class exception is raised.



PLT