Fre*_*d_2 3 lisp common-lisp output
我写了这段代码来写一个文件:
(defun writefile (text filename)
(with-open-file (stream filename :direction :output :if-exists :supersede
:if-does-not-exist :create)
(format stream text)))
Run Code Online (Sandbox Code Playgroud)
但如果我执行,例如:
(writefile '(a b c) "foo.txt")
Run Code Online (Sandbox Code Playgroud)
收益:
错误:在对FORMAT的调用中:(ABC)不是类型(OR STRING FUNCTION).
为什么它会告诉我这个错误?
你的format调用是错误的:第二个参数应该是a
string或a
function(参见错误信息!)
您需要替换它(format stream "~S" text)或只是使用prin1或write.