summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRich Hickey <richhickey@gmail.com>2008-09-06 22:30:50 +0000
committerRich Hickey <richhickey@gmail.com>2008-09-06 22:30:50 +0000
commitfb3aa918c91c1b009c2e97436359c20f355e8430 (patch)
tree5a7ddd772d1124bb4569e7e7d58b13c691106963 /src
parent3f0cef5142672ea1a9f881477135565b316a2796 (diff)
added :refer-clojure support to ns, special resolution of ns and in-ns, moved to ns for inspector/parallel/set/xml/zip
Diffstat (limited to 'src')
-rw-r--r--src/clj/clojure/boot.clj36
-rw-r--r--src/clj/clojure/inspector/inspector.clj10
-rw-r--r--src/clj/clojure/parallel/parallel.clj3
-rw-r--r--src/clj/clojure/set/set.clj3
-rw-r--r--src/clj/clojure/xml/xml.clj8
-rw-r--r--src/clj/clojure/zip/zip.clj4
-rw-r--r--src/jvm/clojure/lang/Compiler.java15
-rw-r--r--src/jvm/clojure/lang/RT.java4
8 files changed, 53 insertions, 30 deletions
diff --git a/src/clj/clojure/boot.clj b/src/clj/clojure/boot.clj
index 3f73b923..e2bb6b54 100644
--- a/src/clj/clojure/boot.clj
+++ b/src/clj/clojure/boot.clj
@@ -2952,27 +2952,37 @@
(print (apply format fmt args)))
(defmacro ns
- "Sets *ns* to the namespace named by name (unevaluated), creating it if needed.
- If the ns didn't already exist, refers the clojure namespace. references can be zero or more of:
- (:require ...) (:use ...) (:import ...) with the syntax of require/use/import respectively,
- except the arguments are unevaluated and need not be quoted. Use of ns is preferred to
- individual calls to in-ns/require/use/import:
+ "Sets *ns* to the namespace named by name (unevaluated), creating it
+ if needed. references can be zero or more of: (:refer-clojure ...)
+ (:require ...) (:use ...) (:import ...) (:load-resources ...) with
+ the syntax of refer-clojure/require/use/import/load-resources
+ respectively, except the arguments are unevaluated and need not be
+ quoted. If :refer-clojure is not used, a default (refer 'clojure)
+ is used. Use of ns is preferred to individual calls to
+ in-ns/require/use/import:
(ns foo
+ (:refer-clojure :exclude [ancestors printf])
(:require (clojure.contrib sql sql.tests))
(:use (my.lib this that))
(:import (java.util Date Timer Random)
- (java.sql Connection Statement)))"
+ (java.sql Connection Statement))
+ (:load-resources \"/mystuff/foo.clj\"))"
[name & references]
(let [process-reference
(fn [[kname & args]]
- `(~(symbol (clojure/name kname))
- ~@(map #(list 'quote %) args)))]
- `(let [existed# (clojure.lang.Namespace/find '~name)]
- (in-ns '~name)
- (when-not existed#
- (clojure/refer '~'clojure))
- ~@(map process-reference references))))
+ `(~(symbol "clojure" (clojure/name kname))
+ ~@(map #(list 'quote %) args)))]
+ `(do
+ (clojure/in-ns '~name)
+ ~@(when (not-any? #(= :refer-clojure (first %)) references)
+ `((clojure/refer '~'clojure)))
+ ~@(map process-reference references))))
+
+(defmacro refer-clojure
+ "Same as (refer 'clojure <filters>)"
+ [& filters]
+ `(clojure/refer '~'clojure ~@filters))
(defmacro defonce
"defs name to have the root value of the expr iff the named var has no root value,
diff --git a/src/clj/clojure/inspector/inspector.clj b/src/clj/clojure/inspector/inspector.clj
index ad5a374e..8a88465b 100644
--- a/src/clj/clojure/inspector/inspector.clj
+++ b/src/clj/clojure/inspector/inspector.clj
@@ -6,12 +6,10 @@
; the terms of this license.
; You must not remove this notice, or any other, from this software.
-(in-ns 'clojure.inspector)
-(clojure/refer 'clojure)
-
-(import '(javax.swing.tree TreeModel)
- '(javax.swing.table TableModel)
- '(javax.swing JTree JTable JScrollPane JFrame))
+(ns clojure.inspector
+ (:import (javax.swing.tree TreeModel)
+ (javax.swing.table TableModel)
+ (javax.swing JTree JTable JScrollPane JFrame)))
(defn atom? [x]
(not (instance? clojure.lang.IPersistentCollection x)))
diff --git a/src/clj/clojure/parallel/parallel.clj b/src/clj/clojure/parallel/parallel.clj
index 8ba70c82..ae177b2f 100644
--- a/src/clj/clojure/parallel/parallel.clj
+++ b/src/clj/clojure/parallel/parallel.clj
@@ -6,8 +6,7 @@
; the terms of this license.
; You must not remove this notice, or any other, from this software.
-(in-ns 'clojure.parallel)
-(clojure/refer 'clojure)
+(ns clojure.parallel)
(alias 'parallel 'clojure.parallel)
(comment "
diff --git a/src/clj/clojure/set/set.clj b/src/clj/clojure/set/set.clj
index 668de4b4..a59fc145 100644
--- a/src/clj/clojure/set/set.clj
+++ b/src/clj/clojure/set/set.clj
@@ -6,8 +6,7 @@
; the terms of this license.
; You must not remove this notice, or any other, from this software.
-(in-ns 'clojure.set)
-(clojure/refer 'clojure)
+(ns clojure.set)
(defn union
"Returns a set that is the union of the two sets."
diff --git a/src/clj/clojure/xml/xml.clj b/src/clj/clojure/xml/xml.clj
index 55a8f140..516eb06d 100644
--- a/src/clj/clojure/xml/xml.clj
+++ b/src/clj/clojure/xml/xml.clj
@@ -6,11 +6,9 @@
; the terms of this license.
; You must not remove this notice, or any other, from this software.
-(in-ns 'clojure.xml)
-(clojure/refer 'clojure)
-
-(import '(org.xml.sax ContentHandler Attributes SAXException)
- '(javax.xml.parsers SAXParser SAXParserFactory))
+(ns clojure.xml
+ (:import (org.xml.sax ContentHandler Attributes SAXException)
+ (javax.xml.parsers SAXParser SAXParserFactory)))
(def *stack*)
(def *current*)
diff --git a/src/clj/clojure/zip/zip.clj b/src/clj/clojure/zip/zip.clj
index 40c765e5..394990c1 100644
--- a/src/clj/clojure/zip/zip.clj
+++ b/src/clj/clojure/zip/zip.clj
@@ -9,8 +9,8 @@
;functional hierarchical zipper, with navigation, editing and enumeration
;see Huet
-(in-ns 'clojure.zip)
-(clojure/refer 'clojure :exclude '(replace))
+(ns clojure.zip
+ (:refer-clojure :exclude (replace)))
(defn zipper
"Creates a new zipper structure.
diff --git a/src/jvm/clojure/lang/Compiler.java b/src/jvm/clojure/lang/Compiler.java
index 7da12352..31cf7024 100644
--- a/src/jvm/clojure/lang/Compiler.java
+++ b/src/jvm/clojure/lang/Compiler.java
@@ -72,6 +72,9 @@ static final Symbol ISEQ = Symbol.create("clojure.lang.ISeq");
static final Keyword inlineKey = Keyword.intern(null, "inline");
static final Keyword inlineAritiesKey = Keyword.intern(null, "inline-arities");
+static final Symbol NS = Symbol.create("ns");
+static final Symbol IN_NS = Symbol.create("in-ns");
+
//static final Symbol IMPORT = Symbol.create("import");
//static final Symbol USE = Symbol.create("use");
@@ -3960,6 +3963,10 @@ static public Object resolveIn(Namespace n, Symbol sym) throws Exception{
{
return RT.classForName(sym.name);
}
+ else if(sym.equals(NS))
+ return RT.NS_VAR;
+ else if(sym.equals(IN_NS))
+ return RT.IN_NS_VAR;
else
{
Object o = n.getMapping(sym);
@@ -3986,6 +3993,10 @@ static public Object maybeResolveIn(Namespace n, Symbol sym) throws Exception{
{
return RT.classForName(sym.name);
}
+ else if(sym.equals(NS))
+ return RT.NS_VAR;
+ else if(sym.equals(IN_NS))
+ return RT.IN_NS_VAR;
else
{
Object o = n.getMapping(sym);
@@ -4010,6 +4021,10 @@ static Var lookupVar(Symbol sym, boolean internNew) throws Exception{
else
var = ns.findInternedVar(name);
}
+ else if(sym.equals(NS))
+ return RT.NS_VAR;
+ else if(sym.equals(IN_NS))
+ return RT.IN_NS_VAR;
else
{
//is it mapped?
diff --git a/src/jvm/clojure/lang/RT.java b/src/jvm/clojure/lang/RT.java
index efc3596c..b8efac2a 100644
--- a/src/jvm/clojure/lang/RT.java
+++ b/src/jvm/clojure/lang/RT.java
@@ -184,6 +184,7 @@ final static public Var USE_CONTEXT_CLASSLOADER =
final static Symbol LOAD_FILE = Symbol.create("load-file");
final static Symbol IN_NAMESPACE = Symbol.create("in-ns");
+final static Symbol NAMESPACE = Symbol.create("ns");
//final static Symbol EXPORTS = Symbol.create("*exports*");
//final static Var EXPORTS_VAR = Var.intern(CLOJURE_NS, EXPORTS, PersistentHashMap.EMPTY);
//final static Symbol EQL_REF = Symbol.create("eql-ref?");
@@ -198,6 +199,9 @@ final static Var PRINT_META = Var.intern(CLOJURE_NS, Symbol.create("*print-meta*
final static Var PRINT_READABLY = Var.intern(CLOJURE_NS, Symbol.create("*print-readably*"), T);
final static Var WARN_ON_REFLECTION = Var.intern(CLOJURE_NS, Symbol.create("*warn-on-reflection*"), F);
+final static Var IN_NS_VAR = Var.intern(CLOJURE_NS, Symbol.create("in-ns"), F);
+final static Var NS_VAR = Var.intern(CLOJURE_NS, Symbol.create("ns"), F);
+
//final static Var IMPORTS = Var.intern(CLOJURE_NS, Symbol.create("*imports*"), DEFAULT_IMPORTS);
final static IFn inNamespace = new AFn(){
public Object invoke(Object arg1) throws Exception{