[plt-scheme] near-copy struct construction?

From: Guillaume Marceau (gmarceau at cs.brown.edu)
Date: Tue Jan 27 20:46:08 EST 2004

Is there a way to copy struct with all fields but a few fields equal their
original value?

In ocaml, this is the "with" operator ocaml for record constructors.

I would call it 'make-struct-with', and it would behave as follow:

> (define-struct stuff (a b c d e) (make-inspector))
> (define s (make-stuff 1 2 3 4 5))
> (struct->vector s)
#6(struct:stuff 1 2 3 4 5)
> (define new-s (make-struct-with s (c 'boo)))
> (struct->vector new-s)
#6(struct:stuff 1 2 boo 4 5)

"The thing I remember most about America is that it's silly.
 That can be quite a relief at times."  -- Thom Yorke, Radiohead

- Guillaume

Posted on the users mailing list.