예제 #1
0
def _pygp_to_number(term):
    if pygprolog.pygp_Type_Of_Term(term) == 3:
        return int(pygprolog.pygp_Rd_Integer(term))
    elif pygprolog.pygp_Type_Of_Term(term) == 4:
        return float(pygprolog.pygp_Rd_Decimal(term))
    else:
        raise Exception(f"term type {pygprolog.pygp_Type_Of_Term(term)} is not a number")
예제 #2
0
def _pygp_to_structure(term):
    v1 = pygprolog.pygp_Mk_Variable()
    v2 = pygprolog.pygp_Mk_Variable()

    pygprolog.pygp_Builtin_Functor(term, v1, v2)

    functor = pygprolog.pygp_Rd_String(v1)
    arity = pygprolog.pygp_Rd_Integer(v2)
    args = []
    for i in range(1, arity+1):
        v = pygprolog.pygp_Mk_Variable()
        pygprolog.pygp_Builtin_Arg(pygprolog.pygp_Mk_Integer(i), term, v)
        args.append(_read_pygp(v))

    # global global_context

    return Structure(c_functor(functor, arity), args)