Skip to content

Instantly share code, notes, and snippets.

@juergenhoetzel
Created August 10, 2010 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juergenhoetzel/518129 to your computer and use it in GitHub Desktop.
Save juergenhoetzel/518129 to your computer and use it in GitHub Desktop.
Monkeying with Clojure’s defmethod Macro
(defmacro defmethod-explicit
[multifn dispatch-val & fn-tail]
(let [[kw n & body] fn-tail]
(if (= :as kw)
`(let [~n ~dispatch-val]
(defmethod ~multifn ~dispatch-val ~body))
`(defmethod ~multifn ~dispatch-val ~fn-tail))))
(defmulti expl-mm (juxt first second))
(defmethod-explicit expl-mm [1 2] :as dv [_] (str dv))
(defmethod-explicit expl-mm [3 4] [s] (reverse s))
(expl-mm [1 2])
(expl-mm [3 4])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment