[racket] struct-copy with sub-types

From: Nadeem Abdul Hamid (nadeem at acm.org)
Date: Tue Mar 22 19:49:34 EDT 2011

Is there anything like struct-copy that works to functionally update a
field value in a structure, where the field happens to be defined in
the super-type? In the example below, I want to "functionally update"
a field of the sub structure inherited from the base definition...

(struct base (a b) #:transparent)
(struct sub base (c) #:transparent)

(define S (sub 1 2 3))

(struct-copy sub S [c 4]) ; works
; doesn't work: (struct-copy sub S [b 4])
(struct-copy base S [b 4]) ; produces a base, not sub

Thanks in advance,

--- nadeem

Posted on the users mailing list.