Exemplo n.º 1
0
def test_term():
    X = BindingVar()
    Y = BindingVar()
    t1 = Callable.build("f", [Callable.build("hallo"), X])
    t2 = Callable.build("f", [Y, Callable.build("HALLO")])
    heap = Heap()
    print t1, t2
    t1.unify(t2, heap)
    assert X.dereference(heap).name()== "HALLO"
    assert Y.dereference(heap).name()== "hallo"
Exemplo n.º 2
0
def test_term():
    X = BindingVar()
    Y = BindingVar()
    t1 = Callable.build("f", [Callable.build("hallo"), X])
    t2 = Callable.build("f", [Y, Callable.build("HALLO")])
    heap = Heap()
    print t1, t2
    t1.unify(t2, heap)
    assert X.dereference(heap).name() == "HALLO"
    assert Y.dereference(heap).name() == "hallo"
Exemplo n.º 3
0
def test_var():
    b = BindingVar()
    heap = Heap()
    b.unify(Callable.build("hallo"), heap)
    assert b.dereference(heap).name()== "hallo"
    a = BindingVar()
    b = BindingVar()
    a.unify(b, heap)
    a.unify(Callable.build("hallo"), heap)
    assert a.dereference(heap).name()== "hallo"
    assert b.dereference(heap).name()== "hallo"
Exemplo n.º 4
0
def test_var():
    b = BindingVar()
    heap = Heap()
    b.unify(Callable.build("hallo"), heap)
    assert b.dereference(heap).name() == "hallo"
    a = BindingVar()
    b = BindingVar()
    a.unify(b, heap)
    a.unify(Callable.build("hallo"), heap)
    assert a.dereference(heap).name() == "hallo"
    assert b.dereference(heap).name() == "hallo"
Exemplo n.º 5
0
 def _term_expand(self, term):
     if self.modulewrapper.system is not None:
         v = BindingVar()
         call = Callable.build("term_expand", [term, v])
         try:
             self.run_query_in_current(call)
         except error.UnificationFailed:
             v = BindingVar()
             call = Callable.build("term_expand", [term, v])
             self.run_query(call, self.modulewrapper.system)
         term = v.dereference(None)
     return term
Exemplo n.º 6
0
 def _term_expand(self, term):
     if self.modulewrapper.system is not None:
         v = BindingVar()
         call = Callable.build("term_expand", [term, v])
         try:
             self.run_query_in_current(call)
         except error.UnificationFailed:
             v = BindingVar()
             call = Callable.build("term_expand", [term, v])
             self.run_query(call, self.modulewrapper.system)
         term = v.dereference(None)
     return term
Exemplo n.º 7
0
def test_run():
    e = Engine()
    e.add_rule(Callable.build("f", [Callable.build("a"), Callable.build("b")]))
    X = BindingVar()
    Y = BindingVar()
    c = Callable.build("f", [X, X])
    e.add_rule(c)
    c2 = Callable.build(":-", [Callable.build("f", [X, Y]),
                           Callable.build("f", [Y, X])])
    e.add_rule(c2)
    hp = Heap()
    X = hp.newvar()
    c3 = Callable.build("f", [Callable.build("b"), X])
    e.run_query_in_current(c3)
    assert X.dereference(hp).name()== "b"
    query = Callable.build("f", [Callable.build("b"), Callable.build("a")]) 
    e.run_query_in_current(query)
Exemplo n.º 8
0
def test_run():
    e = Engine()
    e.add_rule(Callable.build("f", [Callable.build("a"), Callable.build("b")]))
    X = BindingVar()
    Y = BindingVar()
    c = Callable.build("f", [X, X])
    e.add_rule(c)
    c2 = Callable.build(
        ":-", [Callable.build("f", [X, Y]),
               Callable.build("f", [Y, X])])
    e.add_rule(c2)
    hp = Heap()
    X = hp.newvar()
    c3 = Callable.build("f", [Callable.build("b"), X])
    e.run_query_in_current(c3)
    assert X.dereference(hp).name() == "b"
    query = Callable.build("f", [Callable.build("b"), Callable.build("a")])
    e.run_query_in_current(query)