[racket] struct-copy with parent type

From: Nick Shelley (nickmshelley at gmail.com)
Date: Fri May 24 13:18:29 EDT 2013

The struct-copy docs say "The result of struct-expr can be an instance of a
sub-type of id, but the resulting copy is an immediate instance of id (not
the sub-type)." Why is this?

For instance, I would hope this would work:

(struct posn (x y))
(struct 3d-posn posn (z))
(3d-posn-z (struct-copy posn (3d-posn 1 2 3) [x 5]))

My actual use case is that I'm representing some data with structs. I have
the common data in a parent struct and the specific data in the child
structs. One of the common fields is a unique id (a number I just
increment). I'd like to be able to copy a piece of data and just change the
unique id in the struct-copy. Instead I have to have a cond or a match that
does the same struct-copy but with different struct ids for each sub type.

Is there an easier way to do what I'm trying to do?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20130524/fa2b234c/attachment.html>

Posted on the users mailing list.