clojure - Method signature in REPL -


i need use poorly documented java library , me if there way see signature of methods in repl (for quick experiments). consider following:

user=> (import 'x.y.z.c) user=> (show-method-signature 'c/m)          c/m string integer string boolean 

is there tricky method show-method-signature available?

the clojure.reflect library friend here.

(require '[clojure [reflect :as r]])  ;; return method signature methods matching given regex. ;; params: ;;  cls                - class (eg. java.util.list) or instance  ;;  method-name-regex  - regex string match against 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))))) 

you can use follows:

=> (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.*") ;; works 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -