On 8 déc, 23:13, "Michael Reid" <[EMAIL PROTECTED]> wrote: > Then I of course write the implementations for various different > types. Then, because the multi-method names don't look nice, I wrote a > macro which transformed the regular operators into calls on the > multi-methods, i.e.: > > (macroexpand-1 '(extended-math (* 3 A))) --> (mul 3 A) > > Its still not as clean as a having the operators defined as > multi-methods from the get-go, but you don't have to muck with > overriding the core names.
I was trying to do it with namespace but : ns scratch (:refer-clojure :exclude [+ - * /]) (:use clojure.contrib.def)) (defalias * clojure.core/*) (* 2 5) ; 10 (defalias / clojure.core//) ;; #<Exception java.lang.Exception: Invalid token: scratch//> Didn't find why it work in core.clj ??? > One reason to leave the core operators alone is performance. > Multi-method dispatch is far more expensive than a regular dispatch. I > don't have this in front of me to get some real numbers, but when I > tested, the same operations with the multi-methods were about 10x > slower than the direct dispatch. Yes, but it give you some nice abstractions : sort fallback to Comparable interface. If not you would use sort-by and provide a function. An other example : public interface IPersistentVector extends Associative, Sequential, IPersistentStack, Reversible seq & co make Clojure nice and efficient. But I didn't see a simple way to do it in Clojure (it self). May be : (gen-type :name AType :extends [Types...] :methods [aMethode names...]) (gen-instance :name AnInstance :extends [AType Types...]) (defmethod aMethode [#^AnInstance param] (print (param any:))) (def aVar (AnInstance. {any: "Data"})) (aMethode (aVar)) Some day, I would try to do it. pierre --~--~---------~--~----~------------~-------~--~----~ 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 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 -~----------~----~----~----~------~----~------~--~---