3 ms·
Unification of the terms X and Y in the environment E in LISP (part of a PROLOG interpreter): (defun unify (x y e) (let ((x (look-up x e))
by nils-m-holm 7y ago
Unification of the terms X and Y in the environment E in LISP (part of a PROLOG interpreter):
(defun unify (x y e)
(let ((x (look-up x e))
(y (look-up y e)))
(cond ((eq x y) e)
((variable-p x) (cons (list x y) e))
((variable-p y) (cons (list y x) e))
((or (atom x) (atom y)) nil)
(#t (let ((ne (unify (car x) (car y) e)))
(and ne (unify (cdr x) (cdr y) ne)))))))
LOOK-UP looks up X or Y in E, VARIABLE-P returns truth, if X or Y is a
variable.