我是 Lisp 的新手,有一个非常基本的问题。
我正在处理一个包含列表的列表。
(defvar *stationen* nil)
(defun make-station (name uri)
(list :name name :uri uri))
(defun save-db ()
(with-open-file (out "list.txt"
:direction :output
:if-exists :supersede)
(with-standard-io-syntax
(princ *stationen* out))))
(defun load-db ()
(with-open-file (in "list.txt")
(with-standard-io-syntax
(setf *stationen* (READ in)))))
(load-db)
数据包含一个 uri http://www....
。好吧,当我尝试阅读该列表时出现以下错误:
The name "HTTP" does not designate any package.
[Condition of type SB-KERNEL:SIMPLE-PACKAGE-ERROR]
我能猜到为什么会这样(Lisp 试图将“http”解释为一个包,对吧?)。但是我怎样才能将我的 uri 保存到文件中并再次读取它,而 Lisp 不会抛出这个错误?
最佳答案
备选方案:
- 把它写成一个字符串。
- 使用 READ-CHAR、READ-LINE 或 READ-SEQUENCE
- 高级:使用自定义阅读器宏进行读写
顺便说一下,请发布格式化的 Lisp 代码。
关于Lisp:读取包含 url 的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14920285/