the caveat is that the order in which you specify the methods would matter .. since that is the order in which it is going to check for the appropriate method to call.. Just like condp again.
On Thu, Dec 23, 2010 at 10:04 AM, Sunil S Nandihalli < sunil.nandiha...@gmail.com> wrote: > Hi Alex, > I have come across a similar need and I wrote the following macro which > dispatches in a style similar to condp which can achieve what you are asking > for .. > > > https://gist.github.com/752567 > > <https://gist.github.com/752567>basically instead of just having the > dispatch-fn apply only on the arguments of the method and getting the method > corresponding to the value returned .. what the above does is it passes both > the array of all the method arguments and the key- for a given method .. if > that returns true then the corresponding method is called . What this lets > you do is give a meaning to how the value should be compared.. With this > flexibility you can achieve what you want. > > It works exactly like "condp" in terms of chosing the correct method .. > which would correspond to a clause in condp. > > Sunil. > > > On Thu, Dec 23, 2010 at 8:10 AM, Alex Baranosky < > alexander.barano...@gmail.com> wrote: > >> Hi >> >> I've been playing with multimethods, and trying to see if there was a way >> to dispatch on a non-specific result of the dispatching function, such as a >> range, like this: >> >> (defn how-to-move [map1 map2] >> (+ (:cats map1) (:dogs map2))) >> >> (defmulti move how-to-move) >> >> (defmethod move 1 [map1 map2] >> (println "one")) >> >> (defmethod move 2 [map1 map2] >> (println "two")) >> >> (defmethod move 3 [map1 map2] >> (println "three")) >> >> (defmethod move #(> % 3) [map1 map2] >> (println "lots!")) >> >> (move {:cats 1} { :dogs 0}) >> (move {:cats 0} { :dogs 1}) >> (move {:cats 1} { :dogs 1}) >> (move {:cats 1} { :dogs 2}) >> (move {:cats 2} { :dogs 0}) >> (move {:cats 2} { :dogs 5}) >> >> It seems I could easily do this by changing how-to-move to: >> >> (defn how-to-move [map1 map2] >> (let [cnt (+ (:cats map1) (:dogs map2))] >> (if (> cnt 3) >> :lots >> cnt))) >> >> and changing the last move defmethod to: >> >> (defmethod move :lots [map1 map2] >> (println "lots")) >> >> I am wondering if there is a built in syntax for this? >> >> Thanks, >> Alex >> >> -- >> 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<clojure%2bunsubscr...@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 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