• (show x)
  • (show x selector)
With one arg prints all static and instance members of x or (class x).
Each member is listed with a number which can be given as 'selector'
to return the member object -- the REPL will print more details for
that member.

The selector also may be a string or regex, in which case only
members whose names match 'selector' as a case-insensitive regex
will be printed.

Finally, the selector also may be a predicate, in which case only
members for which the predicate returns true will be printed. The
predicate will be passed a single argument, a map that includes the
:text that will be printed and the :member object itself, as well as
all the properies of the member object as translated by 'bean'.

Examples: (show Integer) (show []) (show String 23) (show String "case")

1 Example top

  • (show Integer)
    (show [])
    (show String 23)
    (show String "case")
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/contrib/repl_utils.clj:62 top

(defn show
  "With one arg prints all static and instance members of x or (class x).
  Each member is listed with a number which can be given as 'selector'
  to return the member object -- the REPL will print more details for
  that member.

  The selector also may be a string or regex, in which case only
  members whose names match 'selector' as a case-insensitive regex
  will be printed.

  Finally, the selector also may be a predicate, in which case only
  members for which the predicate returns true will be printed.  The
  predicate will be passed a single argument, a map that includes the
  :text that will be printed and the :member object itself, as well as
  all the properies of the member object as translated by 'bean'.

  Examples: (show Integer)  (show [])  (show String 23)  (show String \"case\")"
  ([x] (show x (constantly true)))
  ([x selector]
      (let [c (if (class? x) x (class x))
            members (sort-by :sort-val
                             (map member-details
                                  (concat (.getFields c)
                                          (.getMethods c)
                                          (.getConstructors c))))]
        (if (number? selector)
          (:member (nth members selector))
          (let [pred (if (ifn? selector)
                       selector
                       #(re-find (re-pattern (str "(?i)" selector)) (:name %)))]
            (println "=== " (Modifier/toString (.getModifiers c)) c " ===")
            (doseq [[i m] (indexed members)]
              (when (pred m)
                (printf "[%2d] %s\n" i (:text m)))))))))
Vars in clojure.contrib.repl-utils/show: constantly defn doseq let nth number? printf println when
Used in 0 other vars

Comments top

No comments for show. Log in to add a comment.