On Thu, Feb 14, 2019 at 9:08 PM Robby Findler <ro...@eecs.northwestern.edu> wrote: > > This is what struct/dc is for. Let me know if the docs let you down! > > Robby
This is good to hear about, because I'm actually in the middle of writing something that it will help with. Thanks, Robby. One question: Is there a typo in the example code or am I missing something? (struct bt (val left right)) (define (bst/c lo hi) (or/c #f (struct/dc bt [val (between/c lo hi)] [left (val) #:lazy (bst lo val)] ; should that be (bt lo val)? What is bst? [right (val) #:lazy (bst val hi)]))) ; and this be (bt val hi) ? Also, am I correct that the contract is not actually attached to the bt structure at this point? That's a thing that would be done elsewhere, probably in the provide statement. Yes? > > On Thu, Feb 14, 2019 at 7:57 PM Chris GauthierDickey <chris...@gmail.com> > wrote: >> >> I'm wondering if it's possible to have a contract for a struct that only >> allows certain kinds of initializations. For example, I have this: >> >> (provide (contract-out >> [struct Result ((name (or/c Temp? Label?)) (global? boolean?) >> (value (or/c VarValue? #f)))])) >> >> But it's too general. What I'd really like to have is a contract that >> combines them like an or/c (I can see what this would cause problems, just >> wondering if there's a clever way around it): >> (provide (contract-out >> [or/c (struct Result ((name Temp?) (global? #f) (value (or/c >> VarValue? #f)))) >> (struct Result ((name Label?) (global? boolean?) (value >> (or/c (VarValue #f)))))])) >> >> In this case, if name is Temp? then global? has to be #f. If name is Label? >> then global? can be #t or #f. I'd like to use struct cause it provides all >> the contracts for accessors and such. Note, I can use a #:guard on the >> struct, but wondered if it was possible to do something along these lines >> with a contract. >> >> Thanks! >> Chris >> >> >> -- >> 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.