[racket] using struct-copy with struct subtypes?

From: Matthew Butterick (mb at mbtype.com)
Date: Mon Nov 17 12:22:35 EST 2014

This seems rudimentary, but I can't figure it out. `struct-copy` requires you to specify the id of the struct type, like so:

(define copied-struct (struct-copy struct-type-id instance-of-struct))

The docs for struct-copy say "subtypes can be copied as if they were supertypes, but the result is an instance of the supertype". [1]

OK, but suppose I want the opposite behavior: I want to make a struct-copying function that accepts instances of a supertype or subtype, but outputs a struct that's the same type as the input instance (not the supertype).

Possible? Or not possible with structs, because that's what objects & classes are for?


[1] http://docs.racket-lang.org/reference/struct-copy.html

Posted on the users mailing list.