[plt-scheme] easy way to extend a #struct to a sub-type?

From: Todd O'Bryan (toddobryan at gmail.com)
Date: Sat Apr 24 21:57:19 EDT 2010

I had hoped that this:

#lang scheme
(define-struct one (a b))
(define-struct (two one) (c))

(define ONE (make-one 2 4))
(define TWO (struct-copy two ONE [c 6]))

would put (make-two 2 4 6) into TWO.

I realize now why it doesn't, but is there a way to just add a
sub-type's fields to a struct value that already exists?

I realize the following works:

(make-two (one-a ONE) (one-b ONE) 6)

but wondered if there were some easier way to do it.

Todd


Posted on the users mailing list.