Beispiel #1
0
def _pair_to_swipy_ref(item: Pair, swipy_ref, lit_var_store: Dict[Variable, int]):
    head = swipy.swipy_new_term_ref()
    tail = swipy.swipy_new_term_ref()

    _to_swipy_ref(item.get_left(), head, lit_var_store)
    _to_swipy_ref(item.get_right(), tail, lit_var_store)

    swipy.swipy_cons_list(swipy_ref, head, tail)
Beispiel #2
0
def _pair_to_pygp(p: Pair, lit_var_store: Dict[Variable, int]):
    left = _to_pygp(p.get_left(), lit_var_store)
    right = _to_pygp(p.get_right(), lit_var_store)

    functor = pygprolog.pygp_Find_Atom('.')
    if functor < 0:
        functor = pygprolog.pygp_Create_Allocate_Atom('.')

    args = [left, right]
    return pygprolog.pygp_Mk_Compound(functor, 2, args)
Beispiel #3
0
def _swipy_to_pair(term):
    head = swipy.swipy_new_term_ref()
    tail = swipy.swipy_new_term_ref()

    swipy.swipy_get_head(term, head)
    swipy.swipy_get_tail(term, tail)

    return Pair(_read_swipy(head), _read_swipy(tail))
Beispiel #4
0
    def test6():
        solver = SWIProlog()

        head = c_pred("head", 2)
        tail = c_pred("tail", 2)
        take_second = c_pred("take_second", 2)
        H = c_var("Head")
        T = c_var("Tail")
        X = c_var("X")
        Y = c_var("Y")

        hatm1 = head(Pair(H, T), H)
        tatm1 = tail(Pair(H, T), T)
        cl = (take_second(X,Y) <= tail(X, T) & head(T, Y))

        solver.assertz(hatm1)
        solver.assertz(tatm1)
        solver.assertz(cl)

        l = List([1,2,3,4,5])
        print(solver.query(take_second(l, X)))

        del solver