let’s try some calls to the “type” function :
user=> (type 10)
java.lang.Integer
user=> (type 10.0)
java.lang.Double
user=> (type :keyword?)
clojure.lang.Keyword
and now with an anonymous function :
user=> (type #(str "wonder" "what" "this" "is"))
user$eval7$fn__8
A) what does this mean “user$eval7$fn__8” ?
B) and what type is a function ?
the source for “type” is :
user=> (source type)
(defn type
"Returns the :type metadata of x, or its Class if none"
{:added "1.0"}
[x]
(or (:type (meta x)) (class x)))
nil
so a function needs to have a specific part of meta data or be a class
checking the meta of an anonymous function yields nada :
user=> (meta #(str "wonder" "what" "this" "is"))
nil
trying a different approach :
user=> (defn woot [] (str "wonder" "what" "this" "is"))
#'user/woot
user=> (meta woot)
{:ns #<Namespace user>, :name woot}
C) seems there is some meta but i figured this is the meta of the symbol “woot”, right ?
what about the second half of the “or” :
user=> (class #(str "wonder" "what" "this" "is"))
user$eval31$fn__32
user=> (class woot)
user$woot
what are these : “user$eval31$fn__32” and “user$woot” and where do they come from ?
checking out the “class” function yields:
user=> (source class)
(defn ^Class class
"Returns the Class of x"
{:added "1.0"}
[^Object x] (if (nil? x) x (. x (getClass))))
nil
and further investigating yields :
user=> (.getClass #(str "wonder" "what" "this" "is"))
user$eval38$fn__39
user=> (.getClass woot)
user$woot
i don’t get it.
D) is this a hashcode : eval38$fn__39 ?
E) is this a symbol : woot ?
F) why doesn’t a function have a type ? isn’t it supposed to be an IFn or something ?
Clojure is built on the JVM.
The JVM doesn’t support first-class functions, or lambdas, out of the box. Every Clojure function, once it is compiled, becomes its own anonymous class from the perspective of the JVM. Each function is, technically, it’s own type.
The class it becomes implements IFn, but when you retrieve it’s type, it gives you the name of the anonymous class which is different every time.