Next: Object 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 (including instances of classes derived from that class) or interface (i.e., instances of classes that implement the interface) and always extracts the value for the same instance variable.

Generic procedures are provided 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. Generic procedures also provide run-time type checking, since a generic procedure only consumes objects of a particular class or interface.

The `make-generic/proc` procedure creates a generic procedure:

- `(make-generic/proc class symbol)` returns a generic procedure that consumes and instance of class (or an instance of a class derived from class) and returns the value of its symbol instance variable.

  If class or its superclasses does not contain an instance variable with the (external) name symbol, the `exn:object` exception is raised by `make-generic/proc`.

- `(make-generic/proc interface symbol)` returns a generic procedure that consumes an instance of any class that implements interface and returns the values of its symbol instance variable.

  If interface does not contain an instance variable with the name symbol, the `exn:object` exception is raised by `make-generic/proc`.

If a generic procedure is applied to an object that is not an instance of the generic procedure's class or interface, the `exn:object` exception is raised.

The `make-generic` form expands to an application to `make-generic/proc`: ``

      (make-generic ci name)

      (make-generic/proc ci (quote name))