我必须构建一个函数来确定我是否有以这种方式构建的格式良好的公式的合取:
cong ::= '(' and wff wff ...')'
假设我有确定公式是否为 wff 的代码。该函数必须首先检查列表的第一个元素是否是'and
,然后递归地检查其余的子列表是否是 wff。请注意,这 p
也是一个 wff,因此它不一定是子列表。
例子 :(and (or a b v) (and a b d) m n)
这是我尝试过的对我不起作用的方法:
(defun cong (fbf)
(and (eq (first fbf) 'and )
(reduce (lambda (x y) (and x y))
(mapcar #'wff (rest fbf)))))