Difference between dot operator and fully qualified named call in Clojure -


i'm learning clojure. still have no understanding language , philosophy.

but want more familiar language. hence have started read clojure core api documentation , found interesting stuffs in clojure.core/get source code.

(defn   "returns value mapped key, not-found or nil if key not present."   {:inline (fn  [m k & nf] `(. clojure.lang.rt (get ~m ~k ~@nf)))    :inline-arities #{2 3}    :added "1.0"}   ([map key]    (. clojure.lang.rt (get map key)))   ([map key not-found]    (. clojure.lang.rt (get map key not-found)))) 

to value given key code uses clojurelang.rt/get function. code calls dot operator - (. clojure.lang.rt (get map key)).

my question why author wrote (. clojure.lang.rt (get map key)) instead of (clojure.lang.rt/get map key).

is there technical difference? or benefit?

the dot in clojure used host interop (with java class clojure.lang.rt in case). idiomatic form static method (classname/staticmethod args*) gets expanded call on . special form. in case of get function, you're looking @ part of clojure's implementation. there's no reason why lower-level clojure code use higher level macro - uses . form directly.

take @ documentation at: http://clojure.org/java_interop

the idiomatic forms @ top , below can find how they're expanded calls on dot operator. here's relevant bit static methods:

(classname/staticmethod args*) ==> (. classname staticmethod args*) 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -