summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRich Hickey <richhickey@gmail.com>2008-08-28 18:05:11 +0000
committerRich Hickey <richhickey@gmail.com>2008-08-28 18:05:11 +0000
commit0ee1610174de367cfd4f7087a3a0ae982bc40c6d (patch)
tree5113a18b4ceee77b65e132a7fe6d13b8d066e3f3
parent4173663ec077ae80945d3dd10175b53f85e9be2e (diff)
added imports, refers, format, printf, ns
-rw-r--r--src/clj/clojure/boot.clj44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/clj/clojure/boot.clj b/src/clj/clojure/boot.clj
index 73380c2f..0fc27f4e 100644
--- a/src/clj/clojure/boot.clj
+++ b/src/clj/clojure/boot.clj
@@ -1488,6 +1488,13 @@
(. ns (importClass c (. Class (forName (str pkg "." c)))))) )
(apply import (rest import-lists))))
+(defmacro imports
+ "import-list => (package-name class-names*)
+
+ For each (unevaluated) name in class-names, adds a mapping from name to the
+ class named by package-name.name to the current namespace."
+ [& import-lists] `(import ~@(map #(list 'quote %) import-lists)))
+
(defn into-array
"Returns an array of the type of the first element in coll,
containing the contents of coll, which must be of a compatible
@@ -1994,6 +2001,23 @@
(throw (new java.lang.IllegalAccessError (str sym " is not public"))))
(. *ns* (refer (or (rename sym) sym) v)))))))
+(defmacro refers
+ "refers to all public vars of ns, subject to filters.
+ filters can include at most one each of:
+
+ :exclude list-of-names
+ :only list-of-names
+ :rename map-of-fromname-toname
+
+ For each public interned var in the namespace named by the symbol,
+ adds a mapping from the name of the var to the var to the current
+ namespace. Throws an exception if name is already mapped to
+ something else in the current namespace. Filters can be used to
+ select a subset, via inclusion or exclusion, or to provide a mapping
+ to a symbol different from the var's name, in order to prevent
+ clashes."
+ [ns-name & filters] `(refer '~ns-name ~@(map #(list 'quote %) filters)))
+
(defn ns-refers
"Returns a map of the refer mappings for the namespace."
[#^clojure.lang.Namespace ns]
@@ -2940,3 +2964,23 @@
"Returns a seq on a java.lang.Enumeration"
[e]
(clojure.lang.EnumerationSeq/create e))
+
+(defn format
+ "Formats a string using java.lang.String.format, see java.util.Formatter for format
+ string syntax"
+ [fmt & args]
+ (String/format fmt (to-array args)))
+
+(defn printf
+ "Prints formatted output, as per format"
+ [fmt & args]
+ (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"
+ [name]
+ `(let [existed# (clojure.lang.Namespace/find '~name)]
+ (in-ns '~name)
+ (when-not existed#
+ (clojure/refer '~'clojure))))