Clojure REPL中的方法签名

Clojure REPL中的方法签名,clojure,Clojure,我需要使用一个文档很差的Java库,如果有办法在REPL中查看方法的签名(用于快速实验),这将对我有所帮助。考虑以下事项: user=> (import 'x.y.z.C) user=> (show-method-signature 'C/m) C/m String Integer String boolean 有没有像show method signature这样的棘手方法可用?clojure.reflect库是您的朋友 (require '[clojure [

我需要使用一个文档很差的Java库,如果有办法在REPL中查看方法的签名(用于快速实验),这将对我有所帮助。考虑以下事项:

user=> (import 'x.y.z.C)
user=> (show-method-signature 'C/m)
         C/m String Integer String boolean

有没有像
show method signature
这样的棘手方法可用?

clojure.reflect库是您的朋友

(require '[clojure [reflect :as r]])

;; Return the method signature for methods matching a given regex.
;; Params:
;;  cls                - a class (eg. java.util.List) or an instance 
;;  method-name-regex  - a regex string to match against the method name 
(defn method-sig [cls method-name-regex]
  (let [name-regex (re-pattern method-name-regex)]
     (filter #(re-matches name-regex (str (:name %)))
             (:members (r/reflect cls)))))
您可以按如下方式使用它:

=> (method-sig java.util.List "add")
;; returns 
({:name add,
  :return-type boolean,
  :declaring-class java.util.LinkedList,
  :parameter-types [java.lang.Object],
  :exception-types [],
  :flags #{:public}}
 {:name add,
  :return-type void,
  :declaring-class java.util.LinkedList,
  :parameter-types [int java.lang.Object],
  :exception-types [],
  :flags #{:public}})

 => (method-sig (java.util.LinkedList.) "add.*") ;; also works