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/swig/python/yapex.py

51 lines
1.2 KiB
Python
Raw Normal View History

2016-04-12 16:22:53 +01:00
# python commands
import sys
import yap
#
# initialize engine
engine = yap.YAPEngine();
# engine = yap.YAPEngine(yap.YAPParams());
def query( s ):
q = engine.query(s)
while q.next():
vs = q.namedVars()
if vs.length() == 0:
print( "yes" )
return
else:
while vs.length() > 0:
eq = vs.car()
print( eq.getArg(1).text() + " = " + eq.getArg(2).text() )
vs = vs.cdr()
if q.deterministic():
return
s = input("next: ?")
if s.find(';') != 0 :
return
print( "no more answers" )
return
def live():
loop = True
while loop:
try:
s = input("?- ")
query( s )
except SyntaxError as err:
print("Syntax Error error: {0}".format(err))
except EOFError:
return
except RuntimeError as err:
print("YAP Execution Error: {0}".format(err))
except ValueError:
print("Could not convert data to an integer.")
except:
print("Unexpected error:", sys.exc_info()[0])
raise
live()