Contents    Page-10    Prev    Next    Page+10    Index   

Backchaining Code, version 2

We can add facts to our list of clauses by making a fact a premise clause with no antecedents; this is the form used in Prolog. Since the premise list is empty, every? returns true.


(defn backch [goal]  ; goal is true
  (some (fn [clause] ; if there is some clause
          (and (= goal (first clause))
                     ; that concludes goal
               (every? backch (rest clause))))
                     ; and every premise is true
        clauses))


(def clauses '((a) (b) (d) (c a b) (e c d)) )

user=> (backch 'e)
true