1
在通用Lisp中,如何讀取&從/到流寫入符號表達式?例如,我可能要編寫一個匿名函數到文件,然後讀取和funcall它:符號表達式流I/O
;;; sexp-io.lisp
;;; Try writing a sexp to file and reading it back in
(with-open-file (file "~/Documents/Lisp/Concurrency/sexp.lisp"
:direction :output :if-exists :supersede)
(print #'(lambda() (+ 1 1)) file))
(with-open-file (file "~/Documents/Lisp/Concurrency/sexp.lisp"
:direction :input)
(read file))
然而,在可疑的輸出碼結果
#<Anonymous Function #x3020018F950F>
這不會導致一個錯誤,當我嘗試閱讀它放回:
> Error: Reader error on #<BASIC-FILE-CHARACTER-INPUT-STREAM ("/Users/frank/Documents/Lisp/Concurrency/sexp.lisp"/7 UTF-8) #x3020018F559D>, near position 3, within "
> #<Anonymous ":
> "#<" encountered.
> While executing: CCL::SIGNAL-READER-ERROR, in process Listener(4).
你究竟想要做什麼? – acelent 2015-03-31 22:49:23