Clisp Error: PRINC: argument is not a stream

Clisp Error: PRINC: argument is not a stream

我正在尝试用 Common Lisp 写入一个文件,但我一直收到 "file is not a stream" 错误:

[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

甚至试图关闭文件 returns 一个错误:

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

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

文件已正确创建,所以我认为这可能是权限问题,但似乎不是。 到目前为止,我已经用谷歌搜索了这个错误,但没有任何运气。有谁知道我做错了什么?谢谢。

PS:我是 运行 Linux Mint 17.3 Rosa with CLISP 2.49 (2010-07-07)

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

的参数

这通常使用方便的宏 with-open-file

files chapter of Practical Common Lisp 展示了如何使用这些以及其他函数和宏。