Skip to content

Instantly share code, notes, and snippets.

@GeorgeJahad
Created April 24, 2011 09:03
Show Gist options
  • Save GeorgeJahad/939421 to your computer and use it in GitHub Desktop.
Save GeorgeJahad/939421 to your computer and use it in GitHub Desktop.
(defmacro remote-declare [name]
"declares the supplied ns-qualified name with no bindings, useful for creating circular dependencies"
(let [[ns v] (.split (str name) "/")
orig-ns (str *ns*)]
`(do (in-ns '~(symbol ns))
(clojure.core/declare ~(symbol v))
(in-ns '~(symbol orig-ns)))))
user> (remote-declare tmp8/a)
#<Namespace user>
user> (defn a[] (tmp8/a))
#'user/a
user> (a)
; Evaluation aborted.
user> *e
#<CompilerException java.lang.IllegalStateException: Var tmp8/a is unbound. (NO_SOURCE_FILE:0)>
user> (ns tmp8)
nil
tmp8> (use 'clojure.core)
nil
tmp8> (defn a [] :a)
#'tmp8/a
tmp8> (ns user)
nil
user> (a)
:a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment