0

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?

象嘉道
  • 3,657
  • 5
  • 33
  • 49

2 Answers2

1

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))
Community
  • 1
  • 1
nha
  • 17,623
  • 13
  • 87
  • 133
0

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.

Nathan Davis
  • 5,636
  • 27
  • 39