【发布时间】:2017-06-09 20:12:17
【问题描述】:
我需要从文件中读取,但我遇到了一些代码问题。我必须像这样阅读 i 文件:
1.0 4.5
4.555 6.43
4.0 5
.....
6 3
每行 2 个数字,由 #\Space 或 #\Tab 分隔(在文件中我可以有很多行)。函数 read 必须返回一个像这样的列表:
((1.0 4.5)(4.555 6.43)(4.0 5)...(6 3))
我尝试过使用with-open-file、read-line 和递归,但在处理流等以正确方式将这些元素放入列表时遇到问题
(with-open-file (in "foo.lisp"
:direction :input
:if-does-not-exist :error)
(myread in))
(defun myread (filename)
(let ((e (read-line filename nil ’eof))))
???
(cons (;;;numbers of current line;;;)(myread (filename)))
我该怎么做?谢谢
【问题讨论】:
标签: file lisp common-lisp