I can convert a string to a sequence, and then convert that sequence to a string representing the sequence.
user=> (str (first (list (seq "(xy)z"))))
"(\\( \\x \\y \\) \\z)"
I can also insert apply into the above form to get the original string back
user=> (apply str (first (list (seq "(xy)z"))))
"(xy)z"
but is there a way to convert a string representing a sequence, to the sequence that the string represents? such as:
"(\\( \\x \\y \\) \\z)"
user=> (some-fn2 "(\\( \\x \\y \\) \\z)")
(\( \x \y \) \z \))
The read-string
function reads a string into a Clojure expression.
(read-string "(\\( \\x \\y \\) \\z)")
(\( \x \y \) \z)
The read family of functions are a big part of what makes Clojure a lisp and the whole "everything is data" mindset. 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)}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With