【发布时间】:2016-04-02 19:30:24
【问题描述】:
我正在尝试用另一个元素替换树中的一个元素。到目前为止,我设法替换了原子,但它不会正确添加到列表中
代码:
(defun replacing (tree trl wrl)
(cond
((null tree) nil)
((atom tree)
(cond ((eql tree trl) (list wrl))
(t (list tree))))
(t (apply 'nconc (mapcar #'(lambda (x) (replacing x trl wrl))
tree)))))
示例:(replacing '(A (B) (C (D) (E))) 'D 'W) -> (A (B) (C (W) (E)))
我得到了什么:(A B C W E)
有什么想法可以改变吗?
【问题讨论】:
标签: tree common-lisp substitution