I have a struct that looks like this (simplified for concision): (struct db-chunk (scratchdir-path chunkdir-path) #:mutable)
I'd like to ensure that: 1) At least one of the fields must be set at creation 2) Both fields will accept only a path-string? value 3) Both fields will return string? when accessed, as that makes it easier to insert into the DB when the time comes. I can put a #:guard parameter on db-chunk that will check #1 and #2 and (if necessary) transform the input into a string in order to satisfy #3, but that only works at initialization. From there I would need to redefine the mutator: (struct db-chunk (scratchdir-path chunkdir-path) #:mutable) (let ([old-mut set-db-chunk-scratchdir-path!]) (set! set-db-chunk-scratchdir-path! (lambda (chnk val) (old-mut chnk (if (path? val) (path->string val) val)))))) Alternatively, I could define my struct and then make a bunch of custom manipulation functions, but then (a) I've got these unguarded functions floating around and (b) I've given up a major advantage of structs, which is their concision. Alternatively again, I could use a class. That would make it easier to add new fields if I need to and to add behavior around the accessors/mutators, but it seems to work against the idea of functional programming. What would you more knowledgeable people recommend as the approach here? -- 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.