Is there a convenient way to check the name of a function which is a parameter of another function? For example,
(defn foo [a-fun] ...)
how should one get the actual name of a-fun inside foo in runtime?
Is there a convenient way to check the name of a function which is a parameter of another function? For example,
(defn foo [a-fun] ...)
how should one get the actual name of a-fun inside foo in runtime?
If you want to get the name of a function, why not pass it as parameter ?
You can get the fully qualified name of a function by using resolve
. Your code would then be called like that :
(defn foo [a-fun]
;; no need to do anything to get the name
)
(foo (resolve 'bar))
No, there is no way to get the name of a function. Why? Because functions do not have names. They might be bound to names in some instances, but even when you define a name for a function, the function itself does not have a name.
For example, if you run:
(macroexpand '(defn foo []))
You wil get:
(def foo (clojure.core/fn ([])))
As you can see, defn
is merely a macro that creates an anonymous function and binds it to a name.