3

I use str to construct strings all the time:

user> (str '(1 2 3) " == " '(1 2 3))
"(1 2 3) == (1 2 3)"

and roughly once a day I get bitten on the ass by:

user> (str '(1 2 3) " == " (map identity '(1 2 3)))
"(1 2 3) == clojure.lang.LazySeq@7861"

I guess I can say:

user> (with-out-str (print '(1 2 3) " == " (map identity '(1 2 3))))
"(1 2 3)  ==  (1 2 3)"

instead, but it seems ugly. Is there a better way?

2 Answers 2

4

You can use print-str:

(print-str '(1 2 3) " == " (map identity '(1 2 3)))
;; => "(1 2 3) == (1 2 3)"
1

You can turn a LazySeq object into a Cons one by using 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)"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.