Hello,
Another thing I often do with records is apply a procedure to the
field values. For example, here are two procedures in a library of mine:
(define (gl-color-rgba color)
(glColor4d (rgba-red color)
(rgba-green color)
(rgba-blue color)
(rgba-alpha color)))
(define (gl-clear-color-rgba color)
(glClearColor (rgba-red color)
(rgba-green color)
(rgba-blue color)
(rgba-alpha color)))
With a "record applier" procedure called 'apply-rgba', those are just:
(define gl-color-rgba (apply-rgba glColor4d))
(define gl-clear-color-rgba (apply-rgba glClearColor))
I added support for this to the 'define-record-type++' macro I mentioned
a few days ago. It's included below; the new part is the
"(define applier ---)"
Ed
(define-syntax define-record-type++
(syntax-rules (fields mutable)
( (define-record-type++
(name constructor predicate cloner assigner applier)
(fields (mutable field accessor mutator changer)
...))
(begin
(define-record-type (name constructor predicate)
(fields (mutable field accessor mutator)
...))
(define (cloner record)
(constructor (accessor record)
...))
(define (assigner a b)
(mutator a (accessor b))
...)
(define applier
(case-lambda ((procedure record)
(procedure (accessor record)
...))
((procedure)
(lambda (record)
(procedure (accessor record)
...)))))
(define (changer record procedure)
(mutator record (procedure (accessor record))))
...
) )))