Node:Accessor, Previous:Class Precedence List, Up:Terminology



3.1.2.3 Accessor

An accessor is a generic function with both reference and setter methods.

(define-accessor perimeter)

Reference methods for an accessor are defined in the same way as generic function methods.

(define-method (perimeter (s <square>))
  (* 4 (side-length s)))

Setter methods for an accessor are defined by specifying "(setter <accessor-name>)" as the first parameter of the define-method call.

(define-method ((setter perimeter) (s <square>) (n <number>))
  (set! (side-length s) (/ n 4)))

Once an appropriate setter method has been defined in this way, it can be invoked using the generalized set! syntax, as in:

(set! (perimeter s1) 18.3)