> When it comes to collections and data structures, what would you all like to > see in Racket2? New APIs? Changes to existing APIs? Whole new paradigms? > Something else?
I wrote the struct-plus-plus module (https://docs.racket-lang.org/struct-plus-plus/index.html) because I wanted some additional features around structs, most of which were available somewhere but not integrated together. struct-plus-plus implements the following: - keyword constructors (already doable with Greg Hendershott's 'struct/kw' code https://www.greghendershott.com/2015/07/keyword-structs-revisited.html) - contracts on individual fields (already doable, but complex: https://docs.racket-lang.org/guide/contracts-struct.html) - defaults for individual fields (the #:auto keyword on fields does not accomplish this, since it only allows one default for the entire struct) - wrappers around fields -- e.g., accept either symbols or strings but normalize to strings- Functional setters and updaters for all fields (doable with Alexis's struct-update module https://docs.racket-lang.org/struct-update/index.html except her version does not enforce contracts on the fields and mine does) I have a few more things I'd like to add: - A 'pre-transform' function that acts as the complement to the wrapper function. The wrapper modifies the data after it's passed through the contract but before the struct is constructed. The 'pre-transform' would modify the data before it goes to the contract. - A way for fields to default based on the values of other fields. Low priority: - mutation-setter/updaters for structs that are marked mutable (not a super high priority for me, since I've come around to thinking that mutable structs are a bad idea in most cases, although I can grant some exceptions) - a keyword for 'don't generate the setter/updaters' for when they aren't desired On Thu, Jan 24, 2019 at 8:34 AM Gustavo Massaccesi <gust...@oma.org.ar> wrote: > > I also like the idea of a contract like "tuple/c", perhaps with a more > rackety name. > > Gustavo > > On Wed, Jan 23, 2019 at 12:02 PM Greg Hendershott <greghendersh...@gmail.com> > wrote: >> >> >> - A separation between using lists as homogeneous collections and using >> >> lists as fixed-size tuples. So there'd be a separate `tuple?` data type >> >> that's structurally equivalent to a list but meant to be used >> >> differently. For example, `(list/c number?)` would mean a list of many >> >> numbers, but `(tuple/c number?)` would mean a tuple of size 1 containing >> >> a number. >> > >> > "It is better to have 100 functions operate on one data structure than 10 >> > functions on 10 data structures.” >> > http://www.cs.yale.edu/homes/perlis-alan/quotes.html >> > "It is better to have 100 transducers operate on one data structure >> > interface than 10 functions on 10 data structures.” Rich Hickey, History >> > of Clojure >> >> Well also, I thought `list/c` already means "tuple"? >> >> (listof number?) is a list of many numbers. >> (list/c number?) is a list of one number. >> >> >> I think it's within the Racket spirit to make a little #lang for >> certain audiences or projects. At some org, "tuple/c" might be a >> helpful alias. Or, for some other team, it's not, and in fact even >> "list/c" is redefined to raise an error, "Please use structs instead >> of ad hoc tuples." >> >> -- >> 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+unsubscr...@googlegroups.com. >> For more options, visit https://groups.google.com/d/optout. > > -- > 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+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.