wro*_*ame 1 lisp file-io common-lisp
我只是想用以下函数写一个文件:
(defun test-save ()
(with-open-file (stream "test.txt" :if-does-not-exist :create)
(format stream "success!")))
Run Code Online (Sandbox Code Playgroud)
但是,输入会(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
Run Code Online (Sandbox Code Playgroud)
更新2:
解决了!我只是不得不使用:if-exists :supersede
尝试添加:direction :output以创建输出文件流:
(with-open-file (stream "test.txt" :direction :output
:if-does-not-exist :create)
(format stream "success!"))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
802 次 |
| 最近记录: |