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

32 прегледа
Пређи на прву непрочитану поруку

Dimaugh Silvestris

непрочитано,
10. 12. 2020. 07:35:3010.12.20.
– 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

непрочитано,
10. 12. 2020. 07:51:1910.12.20.
– Dimaugh Silvestris, Racket Users
(struct fruit () #:super struct:edible #:transparent)

Laurent

непрочитано,
10. 12. 2020. 12:33:5410.12.20.
– 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.
Одговори свима
Одговори аутору
Проследи
0 нових порука