Is it possible to define a substruct with the same fields as its superstruct?

32 views
Skip to first unread message

Dimaugh Silvestris

unread,
Dec 10, 2020, 7:35:30 AM12/10/20
to Racket Users

I'm trying different ways to define a struct that has the same fields as its superstruct without adding any new field, but all I get is errors saying struct expects a list of fields.
Something like:
(struct edible (name grams) #:transparent)
and then
(struct fruit #:super edible #:transparent)
or
(struct fruit edible #transparent)

Of course I could simulate this behavior myself creating different structs and then writing accesors and predicates that would work on all of them, like:
(define edible? (or? fruit? vegetable?  fish?))

But I'd rather ask first if there's an in-built, more elegant way of doing this.

Noah Ma

unread,
Dec 10, 2020, 7:51:19 AM12/10/20
to Dimaugh Silvestris, Racket Users
(struct fruit () #:super struct:edible #:transparent)

Laurent

unread,
Dec 10, 2020, 12:33:54 PM12/10/20
to Noah Ma, Dimaugh Silvestris, Racket Users
or
(struct fruit edible () #:transparent)

On Thu, Dec 10, 2020 at 12:51 PM Noah Ma <noahs...@gmail.com> wrote:
(struct fruit () #:super struct:edible #:transparent)

--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/CAFG7FgVg7D-dUg3Xcw_vHU9%2BXSjRNhjuRVAMLVYNPnZRYXFbRQ%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages