In Clojure, the code (println ["foo" "bar"]) prints the following:
[foo bar]
While the code (println (str "items: " ["foo" "bar"])) prints the following:
items: ["foo" "bar"]
Notice the double quotes around each item in the vector. How can I avoid this? I need a function that concatenates a string with the string representation of a vector, producing this output:
items: [foo bar]
How can I do this in Clojure?
In your example, you don’t really need the string concatenation call to
strbecauseprintlncan take multiple arguments. The following works nicely under Clojure 1.3.0:Edit
I’ve re-read the question, and I’ve realised that Otavio was not only intending to print using the example to illustrate his problem with printing from
str, but also that he does intend to pass concatenated strings to println.Would suggest the following instead:
Output:
References
Docs from the Clojure website under: Other Useful Functions and Macros“:
“…
*print-readably*(which defaults to true) bound to nil, which causes strings to print without surrounding quotes or any escape character encoding, and characters to print without the leading ‘\’, or any escape character encoding. “