Tho*_*hel 4 lisp loops common-lisp unused-variables
有时,我需要迭代 $n$ 次,其中 $n$ 是列表中的元素数量。当然,我可以写这样的东西:
(loop for i from 0 below (list-length l)
do something)
Run Code Online (Sandbox Code Playgroud)
但我更喜欢这样写:
(loop for i from 0
for u in l ; unused 'u' variable
do something)
Run Code Online (Sandbox Code Playgroud)
其中该for u in l部分仅用于在 $n$ 迭代后停止循环。但后来我不使用该u变量,解释器不断抱怨。有什么方法可以处理这种编码风格吗?我应该避免它并使用它list-length吗?
(loop for i from 0
for NIL in l
do something)
Run Code Online (Sandbox Code Playgroud)
NIL 应该这样做。
LOOP 解构模式可以为空,其余列表元素将被忽略。另外:在 LOOP 解构模式中,NIL 表示未使用该变量。