Created
July 1, 2014 13:50
-
-
Save alandipert/a383318cff6f21d309a3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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