def test_unification(self): x = V.make_variable("x") y = V.make_variable("y") pattern = x.pair(y.pair(x)) value = C.make_const(3).pair(L.pair(C.make_const(2))) def check(): assert False pattern.go(value, check)
def test_last(self): a = V.make_variable('a') b = V.make_variable('b') c = V.make_variable('c') x = V.make_variable('x') y = V.make_variable('y') z = V.make_variable('z') p = Prolog() p.fact(x.pair(y.pair(x)).make_const("member")) p.head_body( x.pair(y.pair(z)).make_const("member"), x.pair(y).make_const("member")) p.fact(L.pair(x).pair(x).make_const("append")) p.head_body( a.pair(x).pair(b).pair(c.pair(x)).make_const("append"), a.pair(b).pair(c).make_const("append")) def do(): for q in [x, y]: s = [] p.go( a.pair(q).make_const("member"), lambda: s.append(a.value())) w.append(s) w = [] p.go( x.pair(y).pair(L.make_const('c').make_const('b').make_const( 'a')).make_const('append'), do) self.assertEqual(w, [[], ['a', 'b', 'c'], ['a'], ['b', 'c'], ['a', 'b'], ['c'], ['a', 'b', 'c'], []])
def test_pair(self): assert L.pair(L).car().value() is None assert L.pair(L).cdr().value() is None
def test_occur_check(self): x = V.make_variable('x') x.go(L.pair(x), lambda: self.assertTrue(False))