我正在用 Lisp 编写一个程序,将两个列表中的公共元素放入一个新列表中。这是我的代码。
(defun test (a b)
(let ((alist nil) (blist nil))
(progn
(join a b alist blist)
(print blist))))
(defun join (a b alist blist)
(cond
((and (null a) (null b))
(setf blist (cons alist blist)))
((equal (car a) (car b))
(setf alist (cons (list (car a) (car b)) alist)))
(t (join (cdr a) (cdr b) alist blist))))
但函数的输出始终是nil
。然后我在网上查了一些东西,发现当我尝试使用时setf
,它不再指向原始列表,而是指向一个新列表。所以如果我不能使用setf
,我还能用什么来实现呢?