function/macro | since v0.0-927 | clojure.core/str | Edit |
(str)
(str x)
(str x & ys)
(str)
and (str nil)
return the empty string.
(str x)
returns x.toString()
.
With more than one argument, returns the concatenation of the str
values of
the arguments.
With no args, returns the empty string. With one arg x, returns x.toString(). (str nil) returns the empty string. With more than one arg, returns the concatenation of the str values of the args.
(defn str
([] "")
([x] (if (nil? x)
""
(.join #js [x] "")))
([x & ys]
(loop [sb (StringBuffer. (str x)) more ys]
(if more
(recur (. sb (append (str (first more)))) (next more))
(.toString sb)))))
(core/defmacro str
([] "")
([x]
(if (typed-expr? &env x '#{string})
x
(string-expr (core/list 'js* "cljs.core.str.cljs$core$IFn$_invoke$arity$1(~{})" x))))
([x & ys]
(core/let [interpolate (core/fn [x]
(if (typed-expr? &env x '#{string clj-nil})
"~{}"
"cljs.core.str.cljs$core$IFn$_invoke$arity$1(~{})"))
strs (core/->> (core/list* x ys)
(map interpolate)
(interpose ",")
(apply core/str))]
(string-expr (list* 'js* (core/str "[" strs "].join('')") x ys)))))