Case only works with ints keywords and some other literals (including lists, but don't do that, since it doesn't do what you think it does). While multi-methods work on pretty much anything:
(defmulti first-of-both (fn [a b] [(first a) (first b)])) (defmethod first-of-both [1 1] [a b] (println "one")) (defmethod first-of-both [1 2] [a b] (println "two")) (first-of-both [1] [2]) => "two" (first-of-both [1] [1]) => "one" Timothy On Thu, Jul 10, 2014 at 12:44 PM, Daniel Kersten <dkers...@gmail.com> wrote: > It does work. > > As far as I can tell, the namespace with defmethod must require the > namespace with defmulti and also the namespace with defmethod must be > required from some other namespace that is being executed. > > Eg: > > *foo.clj:* > (ns foo) > (defmulti mmtest identity) > (defmethod mmtest :default [_] (println "default")) > > *bar.clj:* > (ns bar > (:require [foo])) > (defmethod mmtest :bar [_] (println "in bar")) > > *core.clj:* > (ns core > (:require [foo :refer [mmtest]] ; The mm we want to call > [bar])) ; include the :bar impl > > (println "Testing") > (mmtest :bar) ; Prints "in bar" > > > If you don't require bar from core, it will print default instead. > > Note, in this example I require foo and bar from core and use mmtest in > core too - you don't need to require bar from the same namespace that you > use in from like I did here. You just need to make sure that the (defmethod > ...) call gets executed before you call mmtest. > > > > On 10 July 2014 19:09, Elric Erkose <elric.erk...@gmail.com> wrote: > >> This sounds interesting. I tried to define a multimethod in one file and >> a method in another file. I had no success. >> >>> -- >> 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. >> > > -- > 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. > -- “One of the main causes of the fall of the Roman Empire was that–lacking zero–they had no way to indicate successful termination of their C programs.” (Robert Firth) -- 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.