2010-11-07 55 views
3

SEXP如果我寫使用如何從文件中讀取

(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) 

我收到「:INPUT-STREAM不是STREAM類型」錯誤。

(type-of f) 

回報STREAM :: LATIN-1-FILE-STREAM這看起來是至少接近我所需要的。有什麼不同?

如何讀取已寫入文件的列表?

回答

5

您得到的參數爲READ錯誤。它應該只是(read f),而不是(read :input-stream f)

4

您還可以打開文件使用:

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

甚至:

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

:輸入默認的方向。