[racket-users] Re: Looking for idiomatic way to represent very similar but different data types

2021-02-01 Thread jackh...@gmail.com
To make your vector+ operation take an arbitrary number of arguments, this is what I'd do: (define (vector+ . vectors) (vector (for/sum ([v (in-list vectors)]) (vector-i v)) (for/sum ([v (in-list vectors)]) (vector-j v)) (for/sum ([v (in-list vectors)]) (vector-k v (module+

[racket-users] Re: Looking for idiomatic way to represent very similar but different data types

2021-02-01 Thread making-a-racket
Turns out that I don't see a way to calculate the #:auto-value using the constructor fields, so I don't see how to make something like (struct test (x y z [data #:auto]) #:auto-value #(x y z)) work. So I've decided to go with something like this: (struct color (r g b) #:transparent) (struct

[racket-users] Re: Looking for idiomatic way to represent very similar but different data types

2021-02-01 Thread making-a-racket
Apologies. By fourth optional argument, I meant a fourth field with the #auto field option. I'm experimenting with this now. On Monday, February 1, 2021 at 3:24:49 PM UTC-6 making-a-racket wrote: > Thanks for the suggestion and for the macro implementation. I'll have to > pour over that a bit.

[racket-users] Re: Looking for idiomatic way to represent very similar but different data types

2021-02-01 Thread making-a-racket
Thanks for the suggestion and for the macro implementation. I'll have to pour over that a bit. I wanted to do map because I wanted to make it easy to idiomatically implement addition and other such operators on my data types such that they accept arbitrary amounts of arguments and provide the

[racket-users] Re: Looking for idiomatic way to represent very similar but different data types

2021-01-31 Thread jackh...@gmail.com
I'd suggest just going with the structs and making them transparent. It's only three structs and only with a handful of fields, abstracting over them with map and fold doesn't seem worth the added complexity IMO. But if you'd really like to map and fold over structs, I highly recommend using