Clisp错误:PRINC:参数不是流

Clisp错误:PRINC:参数不是流,lisp,common-lisp,clisp,Lisp,Common Lisp,Clisp,我正在尝试用Common Lisp写入文件,但不断出现“文件不是流”错误: [1]>(打开“file.txt”:方向:输出:如果不存在:创建:如果存在:取代) # [2] >(princ'Hello“file.txt) ***-princ:参数“file.txt”不是流 即使尝试关闭文件也会返回错误: [4]> (close "file.txt") *** - no-applicable-method: When calling #<standard-generic-functi

我正在尝试用Common Lisp写入文件,但不断出现“文件不是流”错误:

[1]>(打开“file.txt”:方向:输出:如果不存在:创建:如果存在:取代)
#
[2] >(princ'Hello“file.txt)
***-princ:参数“file.txt”不是流
即使尝试关闭文件也会返回错误:

[4]> (close "file.txt")

*** - no-applicable-method: When calling #<standard-generic-function close>
with arguments ("file.txt"), no method is applicable.
[4]>(关闭“file.txt”)
***-无适用方法:调用时#
对于参数(“file.txt”),没有适用的方法。
该文件是正确创建的,所以我认为这可能是权限问题,但事实并非如此。 到目前为止,我在谷歌上搜索到了这个错误,没有任何运气。有人知道我做错了什么吗?多谢各位


PS:我正在使用CLISP 2.49(2010-07-07)运行Linux Mint 17.3 Rosa

要使用打开的文件,必须保存
open
的返回值,并将其用作
princ
的第二个参数。您还必须使用相同的返回值作为
close
的参数

这通常使用便利宏完成


显示了如何使用这些以及其他函数和宏。

非常感谢!我确实读过关于打开文件的
,但我认为我不允许在作业中使用它。所以我改为:
(setq文件(打开“file.txt”:方向:输出:如果不存在:创建:如果存在:取代))(princ'Hello file)(关闭文件)
,效果很好。@LePoufCelebre注意,这与任何其他编程语言都没有什么不同。例如,在C语言中,您需要执行
intfd=open(“foo.txt”,…);写入(fd,…)
打开(“foo.txt”,…);写(“foo.txt”,…)。或者在java中,您可以执行
FileOutputStream out=newfileoutputstream(“foo.txt”);out.write(…)
,而不是
FileOutputStream out=newfileoutputstream(“foo.txt”);“foo.txt”。写(…)。谢谢@JoshuaTaylor,我不知道这个。
[4]> (close "file.txt")

*** - no-applicable-method: When calling #<standard-generic-function close>
with arguments ("file.txt"), no method is applicable.