我一直使用str来构造字符串:
user> (str '(1 2 3) " == " '(1 2 3))
"(1 2 3) == (1 2 3)"
大约每天一次我被屁股咬伤:
user> (str '(1 2 3) " == " (map identity '(1 2 3)))
"(1 2 3) == clojure.lang.LazySeq@7861"
我想我可以说:
user> (with-out-str (print '(1 2 3) " == " (map identity '(1 2 3))))
"(1 2 3) == (1 2 3)"
相反,但它看起来很难看。还有更好的方法吗?
答案 0 :(得分:4)
您可以使用print-str
:
(print-str '(1 2 3) " == " (map identity '(1 2 3)))
;; => "(1 2 3) == (1 2 3)"
答案 1 :(得分:1)
您可以使用seq
:
user=> (str '(1 2 3) " == " (map identity '(1 2 3)))
"(1 2 3) == clojure.lang.LazySeq@7861"
user=> (str '(1 2 3) " == " (seq (map identity '(1 2 3))))
"(1 2 3) == (1 2 3)"