Can clojure convert a string representing a sequence to a sequence?

I can convert a string to a sequence, and then convert this sequence to a string representing the sequence.

user=> (str (first (list (seq "(xy)z"))))
"(\\( \\x \\y \\) \\z)"

I can also insert a request in the form above to return the original string

user=> (apply str (first (list (seq "(xy)z"))))
"(xy)z"

but is there a way to convert a string representing a sequence into a sequence that a string represents? eg:

"(\\( \\x \\y \\) \\z)"
user=> (some-fn2 "(\\( \\x \\y \\) \\z)")
(\( \x \y \) \z \))
+5
source share
1 answer

The function read-stringreads a string into a Clojure expression.

(read-string "(\\( \\x \\y \\) \\z)")
(\( \x \y \) \z)  

A readable family of functions is a big part of what Clojure a lisp does, and whole thinking is β€œeverything is data.” You can read any form with them:

(read-string "{:a 1 :b 3 :c (1 2 3)}")
{:a 1, :b 3, :c (1 2 3)}
+8
source

All Articles