Lisp 如何从文件中读取sexp

Lisp 如何从文件中读取sexp,lisp,common-lisp,Lisp,Common Lisp,如果我使用 (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)) 创建一个包含以下内容的文件: (1 2 3)(4 5 6)(7 8 9) 但是当我试图打开并阅读它时 (setf f (open "~/exa

如果我使用

(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))
创建一个包含以下内容的文件:

(1 2 3)(4 5 6)(7 8 9)
但是当我试图打开并阅读它时

(setf f (open "~/example.sexp"))
(read :input-stream f)
我得到一个“:输入流不是类型流”错误

返回STREAM::拉丁-1-FILE-STREAM,看起来它至少接近我需要的内容。有什么区别


如何读取已写入文件的列表?

您将要读取的参数设置为错误。它应该是简单的
(读取f)
,而不是
(读取:输入流f)

您也可以在打开文件时使用:

(with-open-file (s "~/example.sexp")
  (read s))
甚至:

(with-open-file (*standard-input* "~/example.sexp")
  (read))
:输入是默认方向

(with-open-file (*standard-input* "~/example.sexp")
  (read))