J'utilise multimethods pour analyser les commandes de ligne de commande et leurs arguments.Comment définir et obtenir des métadonnées multiméthodes dans clojure?
(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)))
Lorsque je tente d'accéder aux métadonnées, pour une méthode spécifique, Clojure retourne nil
:
(meta ((methods run) "help"))