Getting type of function type arguments in Clojure

I'm looking to extract information about the type hints of the function arguments, but I can't find a way to access this information.

For example, let's say I have the following function:

(defn ^Double do-something [^String a, ^String b]
  5.0)

      

Pulling out a tag is simple:

(:tag (meta #'do-something)) ; => java.lang.Double

      

For arguments, however, something like this won't work:

(:arglists (meta #'do-something)) ; => ([a b])

      

It just gives me arguments, not type information. Is there a way to get the type a

and b

?

The reason I want to do this is because I am writing a tool to parse / document functions, and if a function of type is slated, I would like to know that.

Adding hint types to code for the sole purpose of documentation doesn't seem like a particularly great idea, but I'd just like to use this information if it already exists in the first place, and if there is no other type information (like how possible if core.typed ).

+3


source to share


1 answer


You need to get the metadata of the arguments:



user=> (map meta (first (:arglists (meta #'do-something))))
({:tag String} {:tag String})

      

+4


source







All Articles