clojure可以将表示序列的字符串转换回序列吗?

dan*_*lmo 5 string escaping clojure sequence

我可以将字符串转换为序列,然后将该序列转换为表示序列的字符串.

user=> (str (first (list (seq "(xy)z"))))
"(\\( \\x \\y \\) \\z)"
Run Code Online (Sandbox Code Playgroud)

我也可以在上面的表单中插入apply来获取原始字符串

user=> (apply str (first (list (seq "(xy)z"))))
"(xy)z"
Run Code Online (Sandbox Code Playgroud)

但有没有办法将表示序列的字符串转换为字符串表示的序列?如:

"(\\( \\x \\y \\) \\z)"
user=> (some-fn2 "(\\( \\x \\y \\) \\z)")
(\( \x \y \) \z \))
Run Code Online (Sandbox Code Playgroud)

Art*_*ldt 8

read-string函数将字符串读入Clojure表达式.

(read-string "(\\( \\x \\y \\) \\z)")
(\( \x \y \) \z)  
Run Code Online (Sandbox Code Playgroud)

读取函数系列是使Clojure成为lisp和整个"一切都是数据"思维方式的重要组成部分.你可以用它们阅读任何表格:

(read-string "{:a 1 :b 3 :c (1 2 3)}")
{:a 1, :b 3, :c (1 2 3)}
Run Code Online (Sandbox Code Playgroud)