[plt-scheme] can I use struct-copy with inherited fields?

From: Richard Cobbe (cobbe at ccs.neu.edu)
Date: Sun Mar 22 18:04:03 EDT 2009

I'd like to be able to use the `struct-copy' form to update a field that's
inherited from a parent structure.  That is, with the following definitions

    (define-struct a (x y))
    (define-struct (b a) (w z))
    (define b-val (make-b 'x-val 'y-val 'w-val 'z-val))

I'd like the expression (struct-copy b b-val [x-val 3]) to evaluate to
(make-b 3 'y-val 'w-val 'z-val).

The docs for `struct-copy', though, imply that this is not possible, and I
certainly get an error when I try this:

    > (struct-copy b b-val [x 3])
    struct-copy: accessor name not associated with the given structure type in: b-x

Using `struct-copy' on b appears to work only for fields `w' and `z'.

Is there a way around this, or am I stuck?



Posted on the users mailing list.