Skip to content

Instantly share code, notes, and snippets.

@tavisrudd
Created January 19, 2012 22:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tavisrudd/1643214 to your computer and use it in GitHub Desktop.
Save tavisrudd/1643214 to your computer and use it in GitHub Desktop.
add metadata to clojure multifn methods
(defmacro defmethod
"Creates and installs a new method of multimethod associated with dispatch-value. "
{:added "1.0"}
[multifn dispatch-val & fn-tail]
`(. ~(with-meta multifn {:tag 'clojure.lang.MultiFn}) addMethod ~dispatch-val (fn ~@fn-tail)))
(defmacro defmethod-with-metadata
"Creates and installs a new method of multimethod associated with dispatch-value. "
{:added "1.0"}
[multifn dispatch-val & fn-tail]
`(. ~(with-meta multifn {:tag 'clojure.lang.MultiFn})
addMethod
~dispatch-val
(with-meta (fn ~@fn-tail)
~{:ns *ns*
:arglists (list 'quote (list (vec (first fn-tail))))
:name (name multifn)
:line (:line (meta &form))
:file *file*})))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment