Next: SRFI-19, Previous: SRFI-16, Up: SRFI Support
This is an implementation of SRFI-17: Generalized set!
It exports the Guile procedure make-procedure-with-setter under
the SRFI name getter-with-setter and exports the standard
procedures car, cdr, ..., cddddr,
string-ref and vector-ref as procedures with setters, as
required by the SRFI.
SRFI-17 was heavily criticized during its discussion period but it was
finalized anyway. One issue was its concept of globally associating
setter properties with (procedure) values, which is non-Schemy.
For this reason, this implementation chooses not to provide a way to set
the setter of a procedure. In fact, (set! (setter proc)
setter) signals an error. The only way to attach a setter to a
procedure is to create a new object (a procedure with setter) via
the getter-with-setter procedure. This procedure is also
specified in the SRFI. Using it avoids the described problems.
Here is a simple example:
(define car (getter-with-setter car set-car!))
(define cdr (getter-with-setter cdr set-cdr!))
Here is an example that makes define-record-type (see SRFI-9)
accessor and mutator procs easier to handle:
(use-modules (srfi srfi-9))
(define-record-type sprite
(new-sprite x y)
sprite?
(x sprite-x sprite-x!)
(y sprite-y sprite-y!))
(use-modules (srfi srfi-17))
(define sprite-x (getter-with-setter sprite-x sprite-x!))
(define sprite-y (getter-with-setter sprite-y sprite-y!))