[plt-scheme] changing the name of a struct field accessor
Thanks, Matthew. Will this change to "procedure-rename" first appear in
a release in 4.2.4?
Incidentally, what prompted my question was implementing SRFI-9 records
over PLT structs. I ended up using wrappers that call the struct
accessor and mutator procedures returned by "make-struct-type", as an
interim solution. For example:
(define-record-type/write foo
(make-foo aaa bbb)
foo?
foo-write-proc
(aaa foo:aaa)
(bbb foo:bbb foo:set-bbb!)
(ccc foo:ccc))
=expand=>
(define-values (foo make-foo foo? foo:aaa foo:set-bbb! foo:bbb foo:ccc)
(let-values (((type constructor predicate struct-accessor struct-mutator)
(make-struct-type (quote foo)
#f
(+ 1 1)
(+ 1)
#f
(if foo-write-proc
(list (cons prop:custom-write
foo-write-proc))
'()))))
(values
type
(begin (%check-constructor 'define-struct-type/write
constructor
(quote (aaa bbb))
(quote (aaa bbb ccc)))
(let ((make-foo (lambda (aaa bbb)
(constructor aaa bbb))))
make-foo))
(let ((foo? (lambda (x) (predicate x)))) foo?)
(let ((foo:aaa (lambda (x) (struct-accessor x (+))))) foo:aaa)
(let ((foo:set-bbb! (lambda (x v)
(struct-mutator x (+ 1) v))))
foo:set-bbb!)
(let ((foo:bbb (lambda (x) (struct-accessor x (+ 1))))) foo:bbb)
(let ((foo:ccc (lambda (x) (struct-accessor x (+ 1 1))))) foo:ccc))))
(The weirdnesses are due to limitations of "syntax-rules", which I used
just for grins.)
--
http://www.neilvandyke.org/