loops - 不要循环,迭代!(普通 Lisp)
问题描述
我无法切换到某些循环代码的迭代版本:
(defun get-bound-?vars-1 (tree)
(loop for item in tree
when (consp item)
if (member (car item) '(exists forall doall))
nconc (delete-if-not #'?varp
(alexandria:flatten (second item)))
else nconc (get-bound-?vars item)))
我相应的迭代翻译:
(defun get-bound-?vars-2 (tree)
(iter (for item in tree)
(when (consp item)
(if (member (car item) '(exists forall doall))
(nconc (delete-if-not #'?varp
(alexandria:flatten (second item))))
(nconc (get-bound-?vars item))))))
作为测试用例:
(defparameter *tree*
'(if (exists (?t transmitter)
(and (connecting ?t ?connector)
(bind (color ?t $hue))))
(if (not (exists ((?t1 ?t2) transmitter)
(and (connecting ?t1 ?connector)
(connecting ?t2 ?connector)
(bind (color ?t1 $hue1))
(bind (color ?t2 $hue2))
(not (eql $hue1 $hue2)))))
(activate-connector! ?connector $hue))))
然后循环确定:
(get-bound-?vars-1 *tree*) => (?T ?T1 ?T2)
但迭代不行:
(get-bound-?vars-2 *tree*) => NIL
感谢您的任何指示。
解决方案
推荐阅读
- python - python kivy在for循环中生成链接到jsonstore项目的按钮
- android - 如果将新数据添加到服务器,如何刷新应用程序中的 api?改造 2.0
- c# - 更改 url 中的 asp net mvc 控制器名称
- javascript - 使用 Jquery AJAX 调用第三方 API 时出错
- c++ - 返回 std::string 的函数返回零
- c# - 在 c# 中将文本转换为二进制,以 Enter 键作为输入
- python - \n 在 Python 3.6 中不起作用
- r - 变量选择和模型选择
- dll - 以另一个名称从同一目录中的 dll 生成 tlb
- django - 如果来自我的 views.py 的两个值相等,则禁用按钮