如果我用文件写一个文件
(with-open-file (s "~/example.sexp" :direction :output)
(write '(1 2 3) :stream s)
(write '(4 5 6) :stream s)
(write '(7 8 9) :stream s))
Run Code Online (Sandbox Code Playgroud)
创建一个包含的文件
(1 2 3)(4 5 6)(7 8 9)
Run Code Online (Sandbox Code Playgroud)
但是当我尝试打开并阅读它时
(setf f (open "~/example.sexp"))
(read :input-stream f)
Run Code Online (Sandbox Code Playgroud)
我得到一个":INPUT-STREAM不是STREAM类型"错误.
(type-of f)
Run Code Online (Sandbox Code Playgroud)
返回STREAM :: LATIN-1-FILE-STREAM,它看起来至少接近我需要的东西.有什么不同?
如何阅读我写入文件的列表?
您还可以使用 with-open-file:
(with-open-file (s "~/example.sexp")
(read s))
Run Code Online (Sandbox Code Playgroud)
甚至:
(with-open-file (*standard-input* "~/example.sexp")
(read))
Run Code Online (Sandbox Code Playgroud)
:input 是默认方向。