3

我一直使用 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)"

相反,但它看起来很难看。有没有更好的办法?

4

2 回答 2

4

您可以使用print-str

(print-str '(1 2 3) " == " (map identity '(1 2 3)))
;; => "(1 2 3) == (1 2 3)"
于 2013-02-04T13:25:32.890 回答
1

您可以使用以下方法将 LazySeq 对象转换为 Cons 对象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)"
于 2013-02-06T13:58:14.097 回答