Hi,
On 2 Sep., 06:26, HB <[email protected]> wrote:
> How a multimethod in Clojure differs from a method that have multiple
> bodies?
The latter can only dispatch based on the number of arguments and
cannot be extended later on. Compare:
(defmulti foo-multi type)
(defmethod foo-multi String
...)
(defmethod foo-multi Integer
...)
(defmethod foo-multi some.other.Bar
...)
Compare this to:
(defn foo-fn
[x]
(condp #(isa? %2 %1) (type x)
String ...
Integer ...
some.other.Bar ...))
foo-fn cannot be extended after it is defined, while I can still say
later on:
(defmethod foo-multi ::MyType
...)
Hope that helps.
Sincerely
Meikel
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
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