Lurker News
Preferably an elegant snippet rather than an entire (well engineered) codebase.

Comments (380) 116 threads

Show all comments

Showing thread 67 of 116

nils-m-holm#
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.