我使用multimethods来解析命令行命令及其参数。
(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)))
当我尝试访问特定方法的docstring时,clojure会引发异常:
(doc ((methods run) "help"))
ClassCastException clojure.lang.PersistentList cannot be cast to clojure.lang.Symbol clojure.core/find-ns (core.clj:3996)
是否可以在特定方法上设置docstring并稍后在代码中获取它?