我只是想用以下函数写一个文件:
(defun test-save ()
(with-open-file (stream "test.txt" :if-does-not-exist :create)
(format stream "success!")))
但是,输入(test-save)
会产生以下内容:
我在这里做错了什么?
如果重要的话,我在Mac上使用带有SBCL的Cusp for Eclipse。
更新:现在出现这个新错误:
和repl:
COMMON-LISP-USER>
(with-open-file (stream "test.txt" :direction :output
:if-does-not-exist :create)
(format stream "success!"))
error opening #P"/Applications/eclipse/Eclipse.app/Contents/MacOS/test.txt":
File exists
[Condition of type SB-INT:SIMPLE-FILE-ERROR]
0: [ABORT] Return to SLIME's top level.
1: [TERMINATE-THREAD] Terminate this thread (#<THREAD "repl-thread" {12539CB1}>)
]> 0
更新2:
解决!我只需要使用:if-exists :supersede
答案 0 :(得分:6)
尝试添加:direction :output
以创建输出文件流:
(with-open-file (stream "test.txt" :direction :output
:if-does-not-exist :create)
(format stream "success!"))