Unification Code
(defn unify [u v] (unifyb u v '((t t)))) ; unify terms: subst list, nil if failure. (defn unifyb [u v subs] ; unification works if: (and subs (or (and (= u v) subs) ; identical vars (varunify v u subs) ; u is a var (varunify u v subs) ; v is a var (and (cons? u) (cons? v) ; functions (= (first u) (first v)) ; same name (unifyc (rest u) (rest v) subs)) ) ) ) ; and args unify ; unify variable and term if possible ; adds (var term) to subs, or nil (defn varunify [term var subs] (and var subs (symbol? var) (not (occurs var term)) (cons (list var term) (subst term var subs))))