Does that mean one can import all static fields and methods of a class
into the current namespace?
Albert
--
Albert Cardona
http://www.mcdb.ucla.edu/Research/Hartenstein/acardona
> Works for fields, with no parens: Math/PI, or static method
> invocations (Math/sqrt 42)
>
> Feedback welcome,
I like it.
After a few simple examples, I tried this:
(map Math/sqrt (range 100))
which failed.
There is an easy way to get the same effect:
(map #(Math/sqrt %) (range 100))
Would it be possible (efficiently) to make a static method reference
act as a Clojure function in more contexts like as an argument to
map? I curious to know what the issues are with doing that in a
pervasive way.
I've also wondered why you chose / over : as a separator between
namespace and name. The colon seems to fit the role well (an
introducer), doesn't have an existing meaning as the division symbol,
and since keywords are not symbols, it seems using it would be
compatible with their special naming as well. I like /, but I'm
curious if you considered and rejected : and why.
Thanks,
--Steve
Thanks Rich for all your hard work on clojure.
Guillaume.
You see where I'm going, don't you.
Math=> (def PI 3.14)
#'Math/PI
Math=> (clojure/in-ns 'user)
#<Namespace: user>
And now the fun:
user=> Math
class java.lang.Math
user=> Math/PI
3.14
Now everyone can pretend to live in Indiana!
Perhaps I'm only getting what I deserve, but should there be a warning
or something?
--Chouser
That's why I mentioned a warning as opposed to disallowing. If you've
already imported java.lang.Math, (in-ns 'Math) could generate a
warning. If you've already got a Date namespace, then (import
'(java.util Date)) could generate a warning.
Although I suppose then people would want a way to suppress the
warning when they think they know what they're doing.
Perhaps you're right that capitalization will be enough to keep things straight.
--Chouser