1

我正在使用多种方法来解析命令行命令及其参数。

(defmulti run (fn [command args] command))

(defmethod run :default
  [& _]
  ...)

^{:args "[command]"}
(defmethod run "help"
  [_ & [args]]
  "Display command list or help for a given command"
  ...)

^{:args ""}
(defmethod run "version"
  [_ & [args]]
  "Print program's version"
  ...)

(defn -main
  [& args]
  (run (first args)
    (next args)))

当我尝试访问特定方法的文档字符串时,clojure 会引发异常:

(doc ((methods run) "help"))
ClassCastException clojure.lang.PersistentList cannot be cast to clojure.lang.Symbol  clojure.core/find-ns (core.clj:3996)

是否可以在特定方法上设置文档字符串并稍后在代码中获取它?

4

0 回答 0