I'm new on this forum,
i'm trying to develop a lisp application that return T if a clause is a horn clause http://en.wikipedia.org/wiki/Horn_clause (or conjunction of horn clauses) and nil if it isn't.
I wont to clarify that in case of conjunction of horn clauses, the conjucntion could be between * clauses (from 0 to infinite).
I post you the code i've writtent till now that doesn't works and some examples that shloud be verified but (till now they don't) ...maybe somebody could help me to fix it... thank's everybody
Code: Select all
(defun hornp-helper (fbf)
(cond ((or (not (equal 'not (first fbf))) (not (equal 'or (first fbf)))) (horn-positive (rest fbf)))
((equal 'not (first fbf)) (hornp-helper (rest fbf)))
((equal 'and (first fbf)) (horn-positive (rest (rest fbf))))
((null fbf) T)))
(defun horn-positive (fbf)
(cond ((null fbf) T)
((equal 'not (first fbf)) (horn-positive (rest (rest fbf))))
((not (equal 'not (first fbf))) nil)
))
(defun hornp (fbf)
(cond ((equal '==> (first fbf)) (hornp-helper (rest fbf)))
))
NIL
CL-USER>(hornp ’(==> (and p q) r))
T
CL-USER>(hornp ’(==> p (not q))
T