与 read-from-string clisp 相反

Opposite of read-from-string clisp

我想定义一个函数 to-string 执行与以下相反的操作。

> (read-from-string "(foo a b)")
(FOO A B) ;

这似乎有效

(with-output-to-string (s)
  (princ '(1 2 3) s))

函数 write-to-string and prin1-to-string 做你想做的事:

> (read-from-string "(foo \"Hi\" 17)")
(FOO "Hi" 17) ;

> (prin1-to-string '(FOO "Hi" 17))
"(FOO \"Hi\" 17)"
> (write-to-string '(FOO "Hi" 17))
"(FOO \"Hi\" 17)"

函数 write-to-string 还接受允许您调整结果的关键字参数:

> (write-to-string '(FOO "Hi" 17) :case :downcase)
"(foo \"Hi\" 17)"