Previous: , Up: Slots   [Contents][Index]


3.4 Slot Access Procedures

Finally, there is another set of three procedures, which access the contents of a slot directly, given an instance and a slot name. These procedures are very slow by comparison with the above.

However, note the following. You can use these procedures in the body of a define-method special form in an efficient way. If the define-method specifies the correct number of arguments, the body of the form contains a call to one of these procedures and nothing else, and the specified slot name is quoted, the form is rewritten during macro-expansion time as a call to the corresponding method-generating procedure. For example, the following are equivalent:

(define-method p ((v <foo>))
  (slot-value v 'bar))

(add-method p
            (slot-accessor-method <foo> 'bar))
Procedure: slot-value instance name

Returns the contents of the slot name in instance; if the slot is uninitialized, an error of type condition-type:uninitialized-slot is signalled.

Procedure: set-slot-value! instance name object

Modifies the slot name in instance to contain object.

Procedure: slot-initialized? instance name

Returns #t if the slot name in instance is initialized, otherwise returns #f.