Created
August 17, 2011 01:32
-
-
Save drlivingston/1150606 to your computer and use it in GitHub Desktop.
macro for making function
This file contains 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
(defmacro kb-test [name triples & body] | |
`(defn ~name [kb-creator] | |
(binding [*kb* (new-test-kb kb-creator ~triples)] | |
~@body))) | |
create this: | |
user> (macroexpand-1 '(kb-test test-kb-up test-triples | |
(is kb))) | |
(clojure.core/defn test-kb-up [user/kb-creator] | |
(clojure.core/binding [user/*kb* (user/new-test-kb user/kb-creator test-triples)] | |
(is kb))) | |
and when used it creates an error because of user/kb-creator not kb-creator | |
user> (kb-test test-kb-up test-triples | |
(is kb)) | |
Can't use qualified name as parameter: user/kb-creator | |
[Thrown class java.lang.RuntimeException] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the answer is that parameters need to be created with gensym to protect against capture. so that needs to be kb-creator#.