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)

But :square "isa" :rectangle.  What am I doing wrong?
Do I have to define a method for each node in the "derive" hierarchy,
like this?

user=> (defmethod area [:square :side] [s m] (* (:side m) (:side m)))
#<MultiFn clojure.lang.mult...@4dbb9a58>
user=> (area {:shape :square} {:measure :side :side 2})
4

If this is what I have to do, I'm bummed.  I hope I'm doing something
wrong...  can you tell me what it is?
(I'm not looking for a critique of the :measure thing - that doesn't
really play out in this example but
it is useful in other cases not shown here.  Let's stick to the isa?
dispatch question).




--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to