diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/boot.clj | 14 | ||||
-rw-r--r-- | src/jvm/clojure/lang/Compiler.java | 25 |
2 files changed, 36 insertions, 3 deletions
diff --git a/src/boot.clj b/src/boot.clj index 966ae840..0c226432 100644 --- a/src/boot.clj +++ b/src/boot.clj @@ -1672,11 +1672,11 @@ with-local-vars [name-vals-vec & body] (finally (. clojure.lang.Var (popThreadBindings)))))) (defn - #^{:doc "Returns the var or Class to which a symbol will be resolved in the namespace. + #^{:doc "Returns the var or Class to which a symbol will be resolved in the namespace, else nil. Note that if the symbol is fully qualified, the var/Class to which it resolves need not be present in the namespace."} ns-resolve [ns sym] - (. clojure.lang.Compiler (resolveIn ns sym))) + (. clojure.lang.Compiler (maybeResolveIn ns sym))) (defn #^{:doc "same as (ns-resolve *ns* symbol)"} @@ -2061,3 +2061,13 @@ xml-seq [root] (complement string?) (comp seq :content) root)) + +(defn + #^{:doc "Returns true if s names a special form"} +special-symbol? [s] + (contains? (. clojure.lang.Compiler specials) s)) + +(defn + #^{:doc "Returns true if v is of type clojure.lang.Var"} +var? [v] + (instance? clojure.lang.Var v))
\ No newline at end of file diff --git a/src/jvm/clojure/lang/Compiler.java b/src/jvm/clojure/lang/Compiler.java index 376fa4b9..8f36c0c6 100644 --- a/src/jvm/clojure/lang/Compiler.java +++ b/src/jvm/clojure/lang/Compiler.java @@ -74,7 +74,7 @@ static final Symbol ISEQ = Symbol.create("clojure.lang.ISeq"); //static final Symbol IFN = Symbol.create("clojure.lang", "IFn"); -static IPersistentMap specials = RT.map( +static final public IPersistentMap specials = RT.map( DEF, new DefExpr.Parser(), LOOP, new LetExpr.Parser(), RECUR, new RecurExpr.Parser(), @@ -3296,6 +3296,29 @@ static public Object resolveIn(Namespace n, Symbol sym) throws Exception{ } } +static public Object maybeResolveIn(Namespace n, Symbol sym) throws Exception{ + //note - ns-qualified vars must already exist + if(sym.ns != null) + { + Namespace ns = Namespace.find(Symbol.create(sym.ns)); + if(ns == null) + return null; + Var v = ns.findInternedVar(Symbol.create(sym.name)); + if(v == null) + return null; + return v; + } + else if(sym.name.indexOf('.') > 0 || sym.name.charAt(0) == '[') + { + return Class.forName(sym.name); + } + else + { + Object o = n.getMapping(sym); + return o; + } +} + static Var lookupVar(Symbol sym, boolean internNew) throws Exception{ Var var = null; |