Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
user=> (ns there)
nil
there=> (defmulti ^:private doit identity)
#'there/doit
there=> (defmethod doit 1 [x] x)
#<MultiFn clojure.lang.MultiFn@d2de489>
there=> (doit 1)
1
there=> (in-ns 'user)
#<Namespace user>
user=> (defmethod there/doit 2 [x] x)
CompilerException java.lang.IllegalStateException: var: there/doit is not public, compiling:(NO_SOURCE_PATH:21:1)
user=> (defmacro definitely-defmethod
[multifn dispatch-val & fn-tail]
`(. @#'~(with-meta multifn {:tag 'clojure.lang.MultiFn}) addMethod ~dispatch-val (fn ~@fn-tail)))
#'user/definitely-defmethod
user=> (definitely-defmethod there/doit 2 [x] x)
#<MultiFn clojure.lang.MultiFn@d2de489>
user=> (in-ns 'there)
#<Namespace there>
there=> (doit 2)
2
there=>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.