Note also that I'm giving each Zone "object" it's own :type property. That's how I'm able to dispatch on the type. It also plays well with multimethods.
On Saturday, March 5, 2016 at 7:26:27 PM UTC-5, Bobby Eickhoff wrote: > > It sounds like what you're describing is (structurally) an algebraic data > type, i.e. a generic type with specific variants. I've been able to do > something like this in my own projects. Here I'm considering Zone the > general type and each variant is Zone:Hand, Zone:Deck, &c. > > (def Zone:Hand > ...) > > (def Zone:Deck > ...) > > (def Zone > (s/conditional > #(= (:type %) :Hand) Zone:Hand > #(= (:type %) :Deck) Zone:Deck > ...)) > > Does that help? > > On Saturday, March 5, 2016 at 6:58:31 PM UTC-5, JvJ wrote: >> >> I've been using Schema, and there's a kind of type definition that I'm >> having trouble with. I'm not sure exactly how to describe it, so I'll >> provide an example. >> >> I'm working on a digital card game in which there are numerous zones that >> a card may be in. Each card needs to know which zone it is in, and there >> may be additional information depending on the zone. >> >> For instance, if a card is in a player's hand, no additional information >> is required. However, if the card is on the board, it needs to understand >> its position on the board. >> >> I have the following definition for zone types: >> >> (def Zone >> "A schema for referring to the various game zones." >> (s/enum :Hand >> :Deck >> :Board >> :Field >> :Discard >> :Void)) >> >> I want to define a different schema type for each of these, and then >> define a zone spec: >> >> (def ZoneSpec {(required-key :zone-type) Zone >> :data <zone data corresponding to the zone type >> specified earlier> >> }) >> >> I want to ensure that whichever data is provided specified the schema >> associated with the zone type. >> >> Is there a way to do this? >> >> Thanks. >> > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.