• (as-str)
  • (as-str x)
  • (as-str x & ys)
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}"

0 Examples top

Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/contrib/string.clj:315 top

(defn as-str
  "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)))
Vars in clojure.contrib.string/as-str: defn first fn instance? name next str
Used in 0 other vars

Comments top

No comments for as-str. Log in to add a comment.