On 14 Nov., 20:11, Jeff Rose <[EMAIL PROTECTED]> wrote: > Hi, > I'm working on a library where I'd like to be able to dispatch off of > whether the arguments are one of a number of different possible structs. > I've created a custom hierarchy and everything makes sense with derive > etc., but I don't understand how I convert from input values to the > symbols needed for calls to (isa? ...) Anyone know how to do this? Does > my dispatch function have to inspect the passed in values to figure out > which type of struct they are, or can I query that somehow?
Two possible ways to get the “type” of your structure map: 1) (defstruct person :name :age) (defn make-person [name age] (assoc (struct person name age person) :type person)) (defmulti foo :type) (defmethod foo person [person] (println (dissoc person :type))) user> (foo (make-person "Carlos" 13)) {:name Carlos, :age 13} nil 2) Have all persons in one container which will only hold maps that were made via (make-person ...). --~--~---------~--~----~------------~-------~--~----~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---