This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/packages/pyswip/examples/create_term.py
2010-06-01 00:33:32 +01:00

28 lines
681 B
Python

# -*- coding:utf-8 -*-
from pyswip.core import *
from pyswip.prolog import Prolog
def main():
prolog = Prolog()
a1 = PL_new_term_refs(2)
a2 = a1 + 1
t = PL_new_term_ref()
ta = PL_new_term_ref()
animal2 = PL_new_functor(PL_new_atom("animal"), 2)
assertz = PL_new_functor(PL_new_atom("assertz"), 1)
PL_put_atom_chars(a1, "gnu")
PL_put_integer(a2, 50)
#PL_cons_functor(t, animal2, a1, a2)
PL_cons_functor_v(t, animal2, a1)
PL_cons_functor_v(ta, assertz, t)
PL_call(ta, None)
# prolog.assertz("animal(gnu, 50)")
print list(prolog.query("animal(X,Y)", catcherrors=True))
if __name__ == "__main__":
main()