Skip to content

Instantly share code, notes, and snippets.

@jasonjckn
Created June 2, 2011 22:44
Show Gist options
  • Select an option

  • Save jasonjckn/1005509 to your computer and use it in GitHub Desktop.

Select an option

Save jasonjckn/1005509 to your computer and use it in GitHub Desktop.
(defn xform [body [ns v]]
(postwalk (fn [f]
(if (= f ~(symbol v))
`(var ~f)
f)
) body))
(defmacro defparser [name & body]
(try
(eval `(def ~name ~@body))
(catch clojure.lang.Compiler$CompilerException e
(when-let [ec (.getCause e)]
(when-let [parse #(next (re-matches #"Var (\S+)/(\S+) is unbound." %))]
(if-let [ec (.getCause e)]
(eval `(def ~name ~@(xform body (parse (.getMessage ec)))))
(throw)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment