Common lisp allows you to call DEFINE-METHOD-COMBINATION.
(Steele p830) There is a default generic method combination
defined which can be modified by this call.

If Clojure used a function to do the method resolution
then it would be possible to replace this with a user defined
function. This would allow all kinds of dispatching control.

Tim Daly

On 10/25/2010 5:55 PM, Mark Nutter wrote:
So in this particular case I wouldn't care, but in general I'd expect
the prefer-method stuff to kick in. :)
Oops, forgot about prefer-method. My noobishness is showing again.
Well, in for a dime in for a dollar. Here's something I whipped up
just for the general amusement of the list. It's not quite what you
asked for, but it might be suitable as a source of ideas, instruction,
derision, or whatever.

(defmulti bar (fn [x y&  more] [x y]))
(defmethod bar :default [x y&  more]
   (if more ; did default loop back to itself?
        nil
        (some identity [(bar :wild y x)
                  (bar x :wild y)])))
(defmethod bar [:wild 16] [x-wild y&  more]
   (let [x (first more)]
        (str "First arg wild " x ", " y)))
(defmethod bar [42 :wild] [x y-wild&  more]
   (let [y (first more)]
        (str "Second arg wild " x ", " y)))
(defmethod bar [10 20] [x y]
   (pr-str "Plain vanilla args " x ", " y))

user>  (bar 10 20)
"\"Plain vanilla args \" 10 \", \" 20"
user>  (bar 42 20)
"Second arg wild 42, 20"
user>  (bar 10 16)
"First arg wild 10, 16"
user>  (bar 42 16)
"First arg wild 42, 16"user>  (bar 10 20)
"\"Plain vanilla args \" 10 \", \" 20"
user>  (bar 42 20)
"Second arg wild 42, 20"
user>  (bar 10 16)
"First arg wild 10, 16"
user>  (bar 42 16)
"First arg wild 42, 16"


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