Get some basic unification up and running
author |
Steve Losh <steve@stevelosh.com> |
date |
Tue, 08 Mar 2016 15:27:47 +0000 |
parents |
b22eb7fe2faa |
children |
a6a6f6361af3 |
(in-package #:bones-test.paip)
(def-suite :bones.paip)
(in-suite :bones.paip)
(defun alist-equal (x y)
(set-equal x y :test #'equal))
(defmacro unifies (x y bindings)
`(is (alist-equal ,(if (eql bindings 'no-bindings)
'no-bindings
`',bindings)
(unify ',x ',y))))
(defmacro not-unifies (x y)
`(is (eql bones.paip:fail (unify ',x ',y))))
(test constant-unification
(unifies 1 1 no-bindings)
(unifies foo foo no-bindings)
(unifies (a) (a) no-bindings)
(unifies (a b c) (a b c) no-bindings)
(not-unifies 1 2)
(not-unifies foo bar)
(not-unifies a (a))
(not-unifies (a) (a b))
(not-unifies () (a))
)
(test variable-unification
(unifies :x 1 ((:x . 1)))
(unifies :x 2 ((:x . 2)))
(unifies :x a ((:x . a)))
(unifies :x :y ((:x . :y)))
(unifies (likes sally :thing)
(likes :person cats)
((:thing . cats)
(:person . sally)))
(unifies (:x + :y)
(10 + (1 + 2))
((:x . 10)
(:y . (1 + 2))))
(unifies (:x + (:y + :z))
(10 + (1 + 2))
((:x . 10)
(:y . 1)
(:z . 2)))
)