> What's wrong with this: > > user=> (ns test (:use [clojure.contrib.math :exclude (lcm)])) > nil > test=> (sqrt 2) > 1.4142135623730951 > test=> (lcm 3 6) > java.lang.Exception: Unable to resolve symbol: lcm in this context > (NO_SOURCE_FILE:3) > test=> (defn lcm [a b] 1) > #'test/lcm > test=> (lcm 3 6) > 1 > test=>
I think a better example for Mark's concern about existing functions using a faster version of an algorithm would be redefining gcd as this is called by lcm. I tried the following: ---- user=> (ns test (:use [clojure.contrib.math :exclude (gcd)])) nil test=> (gcd 4 6) java.lang.Exception: Unable to resolve symbol: gcd in this context (NO_SOURCE_FILE:3) test=> (lcm 4 6) 12 ---- So it seems lcm is still compiled against the original gcd. Let's try to fix that: ---- test=> (defn clojure.contrib.math/gcd [a b] 1) java.lang.Exception: Can't create defs outside of current ns (NO_SOURCE_FILE:8) test=> (ns clojure.contrib.math) nil clojure.contrib.math=> (defn gcd [a b] 1) #'clojure.contrib.math/gcd clojure.contrib.math=> (ns test) nil test=> (lcm 4 6) 24 ---- Maybe a variant of ns could be written that allows the overriding of specific functions? e.g., ---- (ns2 test (:use [clojure.contrib.math :redef (gcd [a b] 1) (lcm [a b] 2))) ---- Regards, Mark -- http://mark.reid.name --~--~---------~--~----~------------~-------~--~----~ 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---