我在这里检查了如何循环文件的帖子.我在网上检查了几个地方,试图了解在这里发布的代码中发生了什么:
(defun get-file (filename)
(with-open-file (stream filename)
(loop for line = (read-line stream nil)
while line
collect line)))
Run Code Online (Sandbox Code Playgroud)
这种语法似乎是如此神秘,而且引用并不容易理解.根据这里的引用"七个中的第四个/作为语法",语法是:
for var [type-spec] = expr1 [then expr2 ]
如果没有expr2,则使用expr1.
令我困惑的是什么:
除了如何工作之外我不知道该问什么,我迷失了方向:
while line
collect line
Run Code Online (Sandbox Code Playgroud)
我不知道如何用其他代码替换它.它看起来不像一个列表.我的直觉会告诉我它应该看起来像:
(while line (collect line))
Run Code Online (Sandbox Code Playgroud)
此外,不是同样如下:
while line collect line
Run Code Online (Sandbox Code Playgroud)
什么是expr1:
(read-line stream nil)
while line
collect line)
Run Code Online (Sandbox Code Playgroud)
要么
while line
collect line
Run Code Online (Sandbox Code Playgroud)
如果我有更多代码而不是collect line?会不会有名单?我没有看到结构.
我知道这些不仅仅是一个问题,但可能有一些我想念的大事,阻止我提出一个好问题.