www.delorie.com/gnu/docs/guile/goops_13.html   search  
Buy GNU books!

Goops Manual

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ] 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)

  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003