-2 lisp clisp common-lisp
我正在尝试写入Common Lisp中的文件,但我不断收到"文件不是流"错误:
[1]> (open "file.txt" :direction :output :if-does-not-exist :create :if-exists :supersede)
#<output buffered file-stream character #P"file.txt">
[2]> (princ 'Hello "file.txt")
*** - princ: argument "file.txt" is not a stream
Run Code Online (Sandbox Code Playgroud)
即使尝试关闭该文件也会返回错误:
[4]> (close "file.txt")
*** - no-applicable-method: When calling #<standard-generic-function close>
with arguments ("file.txt"), no method is applicable.
Run Code Online (Sandbox Code Playgroud)
该文件已正确创建,因此我认为它可能是一个权限问题,但似乎并非如此.到目前为止,我已经用Google搜索了这个错误.有谁知道我做错了什么?谢谢.
PS:我正在使用CLISP 2.49(2010-07-07)运行Linux Mint 17.3 Rosa
要使用打开的文件,必须保存返回值open并将其用作第二个参数princ.您还必须使用相同的返回值作为参数close.
这通常使用带有open-file的方便宏来完成.
Practical Common Lisp的文件章节展示了如何使用这些以及其他功能和宏.