On Sep 11, 2008, at 8:12 AM, Rich Hickey wrote: Using the latest syntax is good, although the idiom for static calls is (Classname/method args). For instance:
(clojure.lang.Namespace/find sym)
instead of:
(.find clojure.lang.Namespace sym)
because static methods really aren't functions taking classes, but functions in a class namespace.
I see now, cool. I think it's close. The other tip I have is that by type-hinting the- ns you can avoid the hint in every let:
(defn #^{:private true :tag clojure.lang.Namespace} the-ns ...)
(defn ns-name "Returns the name of the namespace, a symbol." [ns] (let [ns (the-ns ns)] (.getName ns)))
getName is a non-reflective call.
I made that change and then removed the let altogether when ns was used only once. I also remove the call to the-ns in the one case (ns-imports) where ns was only being passed along to another ns- function.
I tried to verify that removing the let wouldn't interfere with making it a non-reflective call, but I wasn't able to get any calls to these functions to give me a reflection warning even if I removed the ":tag" from 'the-ns. Was this the right way to test that:
user=> (binding [*warn-on-reflection* true] (ns-name 'clojure)) If you could make these changes I'll incorporate the patch, thanks!
You're quite welcome. Thanks for all the tips. If it needs further refinement, please let me know.
--Steve
|
ns-symbol-2.patch
Description: Binary data