【发布时间】:2021-08-21 08:02:39
【问题描述】:
我试图使用标准循环工具来收集结果,但它只返回 nil。为什么是这样?感觉这应该可行:
(defun coll-intersects (bounds mv)
(let ((res (list))
(loop for x from (first bounds) to (+ (first bounds) (third bounds)) do
(loop for y from (second bounds) to (+ (second bounds) (fourth bounds))
if (not (member (cl-byte (aref mapa x y)) mv))
collect (aref mapa x y) into res
))))
但不,我必须这样做:
(defun coll-intersects (bounds mv)
(let ((res (list)))
(loop for x from (first bounds) to (+ (first bounds) (third bounds)) do
(loop for y from (second bounds) to (+ (second bounds) (fourth bounds))
do
(if (not (member (cl-byte (aref mapa x y)) mv))
(push (aref mapa x y) res))
))
res))
为什么?我真的很困惑为什么第一个不起作用
【问题讨论】:
-
是复制粘贴错字吗?第一个示例的
let缺少右括号:(let ((res (list)))。您的 Lisp 应该警告您有关格式错误的 let 绑定。 -
对不起,这是我尝试过的东西的娱乐。在我尝试过的那个中,我没有错过那个右括号
标签: loops common-lisp