What type is a function?

Viewed 2274

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 ?

4 Answers
Related