Created
April 24, 2011 09:03
-
-
Save GeorgeJahad/939421 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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