Skip to content

Instantly share code, notes, and snippets.

@drlivingston
Created August 17, 2011 01:32
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 drlivingston/1150606 to your computer and use it in GitHub Desktop.
Save drlivingston/1150606 to your computer and use it in GitHub Desktop.
macro for making function
(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]
@drlivingston
Copy link
Author

the answer is that parameters need to be created with gensym to protect against capture. so that needs to be kb-creator#.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment