1

I'm using multimethods to parse command line commands and their arguments.

(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)))

When I try to access the docstring for a specific method, clojure raises an exception:

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

Is it possible to set a docstring on a specific method and get it in the code later?

Aleksei Zyrianov
  • 2,294
  • 1
  • 24
  • 32

0 Answers0