Thank you, gentlemen. Jim and Luc, your answers are both helpful. Luc's
answer illustrates why a Java tyro often has problems understanding
Clojure. Somebody like me who is trying to master Clojure, having come
to it via a language path that doesn't include Java, needs a
prerequisite crash course in Java concepts. (I hope it isn't necessary
for him actually to learn Java programming skills. Reserving
programming-skill learning for Clojure is a lot more fun!) Anybody have
any recommendations of a book that could be used for such a crash course?
--Larry
On 12/16/12 1:53 PM, Softaddicts wrote:
First example tries to access a public static field in the Math class.
Second example calls the static member function of the Math class.
The difference is in the missing set of parenthesis.
A static field or member function is attached to the class, not to a specific
object
and can be accessed through the class itself. Hence the / notation.
On the other hand, (.addListener x ...) refers to the member fn addListener of
the given object x.
You will rarely find Java object specific public fields directly accessible,
most of the
time you need to use a getter to access them, hence the profusion of .getXzzz
when you look at interop code.
Static fields attached to a class are most of the time immutable, they are a way
to make constants public and avoid the getter wrapper syndrom.
Last thing, a class can define classes so you may need to access
Aclass$Bclass/field to get access to a class static field defined within a
class.
This does not apply to an object of class B, the usual (.memberFn object ...)
would still apply assuming you are handed an object created from an inner class.
Luc P.
It almost certainly has something to do with my abysmal ignorance about
things Java, but I don't understand this difference:
(1)
user> (map Math/sqrt [5 6 16])
Unable to find static field: sqrt in class java.lang.Math
[Thrown class java.lang.RuntimeException]
(2)
user> (map #(Math/sqrt %) [5 6 16])
(2.23606797749979 2.449489742783178 4.0)
Thanks for helping me understand.
--Larry
--
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
--
Softaddicts<lprefonta...@softaddicts.ca> sent by ibisMail from my ipad!
--
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