Re: [racket-users] Struct subtype with default/fixed value of super-type

2019-03-20 Thread Jérôme Martin
To go further, if you wonder how to make this work for `match` and inheriting, see this stackoverflow question: https://stackoverflow.com/questions/55262818/how-to-override-a-struct-constructor-while-still-providing-the-struct-metadata-f On Mon, Mar 18, 2019 at 3:08 PM Marc Kaufmann wrote: >

Re: [racket-users] Struct subtype with default/fixed value of super-type

2019-03-18 Thread Marc Kaufmann
While I did know that I could define my own, I was going to do it while providing-out another function make-fish and make-shark, but it's nice to know that this allows me to locally define make-fish, while it looks to the outside like (fish ...). Thanks to including sufficient numbers of mundane

Re: [racket-users] Struct subtype with default/fixed value of super-type

2019-03-18 Thread Jérôme Martin
Once you discover that the default constructor for a struct is just a simple procedure that was generated for you, it's not that big of deal to just make your own and export it like this: (provide (except-out (struct-out fish) fish) (rename-out (make-fish fish))) All the code relying on it

Re: [racket-users] Struct subtype with default/fixed value of super-type

2019-03-18 Thread Marc Kaufmann
Yes, I saw that, the problem is that I want to be able to set a (potentially different) default value for the sub-type shark than for the sub-type guppy. So if I set the value to 'big for all `fish`, then I can't do that. Essentially, I'd need an #:auto for every sub-type, but the #:auto refers to

[racket-users] Struct subtype with default/fixed value of super-type

2019-03-16 Thread Luis Sanjuán
Maybe #:auto/#:auto-value is what you want: ``` (struct fish (name [size #:auto]) #:auto-value 'big #:transparent) (struct shark fish (scares-people?) #:transparent) (define white-shark (shark "The big white" #t)) ``` -- You received this message because you are subscribed to the Google

[racket-users] Struct subtype with default/fixed value of super-type

2019-03-15 Thread Marc Kaufmann
Hi all, suppose I have a struct `(struct fish (size name) #:transparent)` and a sub-type `(struct shark fish (scares-people?) #:transparent)`. What if I want all sharks to have size 'large by default whenever I create one, so that I create them via: (define white-shark (shark "The big white"