aboutsummaryrefslogtreecommitdiff
path: root/src/clojure/contrib/java_utils.clj
diff options
context:
space:
mode:
authorStuart Halloway <stu@thinkrelevance.com>2009-08-23 12:22:49 -0400
committerStuart Halloway <stu@thinkrelevance.com>2009-08-23 12:22:49 -0400
commit6b763062af9568c1b069d5f86c8d5481a3fdfeea (patch)
treef83f33e12cd5eb07244563eb5ccd2d08c4db8eb1 /src/clojure/contrib/java_utils.clj
parent07eef46b22f27a61784c11be03ff0159fac50b38 (diff)
parent835bfe2a02c70c150f2354f8ef9e866f3e2fd180 (diff)
Merge branch 'master' of git@github.com:richhickey/clojure-contrib
Diffstat (limited to 'src/clojure/contrib/java_utils.clj')
-rw-r--r--src/clojure/contrib/java_utils.clj28
1 files changed, 23 insertions, 5 deletions
diff --git a/src/clojure/contrib/java_utils.clj b/src/clojure/contrib/java_utils.clj
index 6944f9ee..579d1128 100644
--- a/src/clojure/contrib/java_utils.clj
+++ b/src/clojure/contrib/java_utils.clj
@@ -90,11 +90,29 @@
(reduce file (file parent child) more)))
(defn as-str
- "Returns the name or string representation of x"
- [x]
- (if (instance? clojure.lang.Named x)
- (name x)
- (str x)))
+ "Like clojure.core/str, but if an argument is a keyword or symbol,
+ its name will be used instead of its literal representation.
+
+ Example:
+ (str :foo :bar) ;;=> \":foo:bar\"
+ (as-str :foo :bar) ;;=> \"foobar\"
+
+ Note that this does not apply to keywords or symbols nested within
+ data structures; they will be rendered as with str.
+
+ Example:
+ (str {:foo :bar}) ;;=> \"{:foo :bar}\"
+ (as-str {:foo :bar}) ;;=> \"{:foo :bar}\" "
+ ([] "")
+ ([x] (if (instance? clojure.lang.Named x)
+ (name x)
+ (str x)))
+ ([x & ys]
+ ((fn [#^StringBuilder sb more]
+ (if more
+ (recur (. sb (append (as-str (first more)))) (next more))
+ (str sb)))
+ (new StringBuilder #^String (as-str x)) ys)))
(defn get-system-property
"Get a system property."