Hi,
I would like to use multimethods by dispatching on keys of the
variables (maps)
in a way that I sometimes have constraints on only some of the
arguments.
In common lisp I would say
(defgeneric foo (a b))
(defmethod foo ((a bar) b) ...)
(defmethod foo (a (b baz)) ...)
(defmethod foo ((a bar) (b baz)) ...)
This would mean that I have also defined methods for calls when (for
example)
`a' is an instance of `bar' and `b' of anything but `baz'. How can I
achieve
something like this with multimethods?
I could define a relationship like
(derive :bar :anything)
(derive :baz :anything)
and then do
(defmulti foo (fn [a b] [(:somekey1 a) (:somekey2 b)]))
with
(defmethod foo [:bar :anything] [a b] ...)
(defmethod foo [:anything :baz] [a b] ...)
(defmethod foo [:bar :baz] [a b] ...)
This seems to do the trick... but is this really the way to do it?
If it is, it would be very useful to have something that is the
ancestor of
everything (like T in common lisp).
Thanks,
Peter
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---