我被一个家庭作业问题困住了。我正在尝试定义一个函数,该函数使用递归检查列表中是否存在元素。下面是我所拥有的。
(defun is-member2 (X S)
"Check if a X is a member of S"
(if (and (atom X) (not (null S)) (lisp S) (> (length S) 0))
;X- is a value, not a set
(if (equal X (car S))
;Located
(equal 'a 'a)
;NotLocated
(is-memeber2 X (cdr S))
)
;No- X is not a value
()
);end if
)
但是,我不断得到它is-memeber2
是未定义的。这让我相信要么X
不再是有效元素,要么 ( cdr S
) 正在发送nul
,但我的 if 语句不应该抓住这个吗?