How to get function's name as string in Clojure?

后端 未结 3 1511
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-13 03:50

How can you get function\'s name as string in Clojure?

What I have so far doesn\'t look anywhere near idiomatic:

(defn fn-name
  [f]
  (first (re-find #\         


        
3条回答
  •  抹茶落季
    2021-02-13 04:39

    For functions defined with the defn form:

    user> (-> #'map meta :name)
    map
    user> (defn nothing [& _])
    #'user/nothing
    user> (-> #'nothing meta :name)
    nothing
    

    This requires access to the var, rather than just the function value the var holds.

提交回复
热议问题