【发布时间】:2013-02-12 15:07:53
【问题描述】:
我必须构建一个函数来确定我是否有以这种方式构建的格式良好的公式的合取:
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)))))
【问题讨论】:
-
你运行它时它做了什么?
-
CL-USER 27 : 7 > (cong '(and a b c d)) Error: Cannot take CAR of A.
标签: lisp conjunctive-normal-form