How to get metadata of clojure function arguments?

Is there a way to get metadata for function arguments in clojure? The answer posed in this question does not actually work at all:

user> (defn foo "informative dox!" [] 1) #'user/foo user> (defmacro get-docs [func] `(:doc (meta (var ~func)))) #'user/get-docs user> (get-docs foo) "informative dox!" user> (get-docs (identity foo)) ; Evaluation aborted. user> (defn process-docs [f] (let [docs (get-docs f)] (reverse docs))) ; Evaluation aborted. 

The second line does not work because you cannot call var in the list (identity foo) , and the last line does not even compile, because the compiler complains about the impossibility of solving f .

Most of the solutions to this problem that I found rely on the idea that you have access to a character in a function definition or something like that so you can do something like (resolve 'f) or (var f) . But I want something that I can use for function arguments, where you do not know this information.

Essentially, I would like to express an expression that can be substituted for the question marks below to get the #'map metadata:

 (let [x map] (??? x)) 
+4
source share
1 answer

his sip, although it is possible:

 (let [x map] (:doc (meta (second (first (filter #(and (var? (second %)) (= x (var-get (second %)))) (ns-map *ns*))))))) 

gives the desired result:

 "Returns a lazy sequence consisting of the result of applying f to the set of first items of each coll, followed by applying f to the set of second items in each coll, until any one of the colls is\n exhausted. Any remaining items in other colls are ignored. Function f should accept number-of-colls arguments." 

under the hood, Namespaces are essentially name cards for vars, and vars contain functions. you can find the contents of these vars for the one that matches the function you are looking for , and then look at the associated var and get the metadata from that var.

+5
source

Source: https://habr.com/ru/post/1434308/