Python “dir” equivalent in Clojure

后端 未结 2 2003
囚心锁ツ
囚心锁ツ 2021-02-05 13:12

Does anybody know if there is a Clojure equivalent for Pythons \"dir\". Basically I need to know the functions I can call on something or more specifically for java objects I wa

2条回答
  •  北荒
    北荒 (楼主)
    2021-02-05 14:01

    clojure.contrib.repl-utils/show for use at the REPL:

    user=> (use '[clojure.contrib.repl-utils :only (show)])
    nil
    user=> (show String)
    ===  public final java.lang.String  ===
    [ 0] static CASE_INSENSITIVE_ORDER : Comparator
    [ 1] static copyValueOf : String (char[])
    [ 2] static copyValueOf : String (char[],int,int)
    [ 3] static format : String (Locale,String,Object[])
    [ 4] static format : String (String,Object[])
    ...
    

    Alternatively, maybe something like:

    user=> (map #(.getName %) (.getMethods String))
    ("equals" "toString" "hashCode" "compareTo" ...)
    

    .getFields, and .getConstructors accordingly.

提交回复
热议问题