【发布时间】:2013-12-23 00:39:57
【问题描述】:
我在 LISP 中有这个例子,它从列表的每一层中删除一个给定的数字:
(defun remove_aux (e l)
(cond
((equal e l) nil)
((atom l) (list l))
(t(list(apply 'append (mapcar #'(lambda (l) (remove_aux e l)) l))))))
(defun remove_el (e l)
(car (remove_aux e l)))
所以,如果它像这样运行:(remove_el 2 '(1 2 3 ((2 3 2) 4))) => (1 3 ((3) 4))
我不太明白这条线是如何工作的:(t(list(apply 'append (mapcar #'(lambda (l) (sterge_aux e l)) l))))
如果我有没有列表的行并附加((t(mapcar #'(lambda (l) (remove_aux e l)) l))),结果是((1) NIL (3) ((NIL (3) NIL) (4)))) 如果它有附加但没有列出( (t(apply 'append (mapcar #'(lambda (l) (remove_aux e l)) l))) ),那么结果是(1 3 3 4),我不明白为什么,因为我做了@987654327 @ 在 Common Lisp 控制台中,结果是 ((1 3 (NIL (3) NIL) (4))) 所以我真的很困惑。有人可以逐步向我解释这一切是如何工作的吗?
【问题讨论】:
-
这看起来很难看。可以格式化一下代码吗?
标签: lisp common-lisp