Skip to content

Instantly share code, notes, and snippets.

@zippy
Created May 11, 2011 14:58
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 zippy/966613 to your computer and use it in GitHub Desktop.
Save zippy/966613 to your computer and use it in GitHub Desktop.
clojure macro instantiation error
(defmacro make-obj [n & args]
(let [name (if (instance? clojure.lang.Symbol n) n (eval n))]
`{(keyword '~name) [~@args]} ))
(make-obj bar :foo) ; => {:bar [:foo]}
(make-obj (symbol (str (name :bar))) :foo) ; => {:bar [:foo]}
(defmacro make-fn [n & b] `(defn ~n ~@b))
(make-fn keyword-maker [k] (make-obj (symbol (str (name k))) :foo)) ;=> Thrown class java.lang.InstantiationException
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment