On Wed, Oct 21, 2009 at 2:49 PM, Shel <skap...@gmail.com> wrote: > > Hi, I'm having a bit of trouble with the supposed use of isa? as a > part of multimethod dispatch. > Consider the following example: > > (defmulti area (fn [s m] [(:shape s) (:measure m)])) > (defmethod area[:rectangle :side] [s m] (* (:side m) (:side m))) > (defmethod area[:rectangle :sides] [s m] (* (:side1 m) (:side2 m))) > (derive ::square ::rectangle) > > user=> (isa? ::square ::rectangle) > true > user=> (area {:shape :square} {:measure :side :side 2}) > java.lang.IllegalArgumentException: No method in multimethod 'area' > for dispatch value: [:square :side] (NO_SOURCE_FILE:0)
:square is not the same as ::square user=> (isa? :square ::square) false user=> (isa? :square :rectangle) false Try this instead. Note the consistent use of :: keywords for values that participate in the 'isa?' test: (defmulti area (fn [s m] [(:shape s) (:measure m)])) (defmethod area [::rectangle ::side] [s m] (* (:side m) (:side m))) (defmethod area [::rectangle ::sides] [s m] (* (:side1 m) (:side2 m))) (derive ::square ::rectangle) user=> (area {:shape ::square} {:measure ::side :side 2}) 4 --Chouser --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---