pyswip
pyswip copied to clipboard
Problem while printing result of query
Hi there,
Thanks for this amazing module.
I think there is a problem with the way terms are printed. I run some Prolog code from Python, querying Prolog with:
H = pyswip.Variable()
induce = pyswip.Functor('induce', 1)
q = Query(induce(H))
q.nextSolution()
print(H.value)
I get a result like this for H:
[Functor(319757,2,
[Functor(9048461,3,_10560234,_10560236,_10560238), Functor(9044237,2,_10560234,_10560238),
Functor(9040141,2,_10560238,_10560236), Functor(9036045,2,_10560238,_10560274),
Functor(9036045,2,_10560236,_10560286), Functor(1724685,2,_10560274,_10560286)],
[Functor(188685,2,_10560234,unit), Functor(188685,2,_10560236,unit), Functor(188685,2,_10560238,unit),
Functor(188685,2,_10560286,time), Functor(188685,2,_10560274,time)])]
where I should get:
[[unconformity(A,C,B),above(A,B),touch(B,C),has_period(B,D),has_period(C,E),D\=E]/[A:unit,C:unit,B:unit,E:time,D:time]]
Strangely, it I print H.value[0].name, I have the correct name for the functor.
This is with Python 3.7, SwiPL 8.0.3, PySwip 0.2.10 under Windows 10.
Regards,
I'm using the following function for converting the output to a String that I could feed back into Prolog:
def pyswip_output_to_str(inp) -> Union[str, int, List]:
if type(inp) is bytes:
inp: bytes
return f'"{inp.decode("utf-8")}"'
elif type(inp) is int:
inp: int
return inp
elif type(inp) is pyswip.easy.Variable:
inp: pyswip.easy.Variable
if inp.chars is None:
return f"_{inp.handle}"
else:
return inp.chars
elif type(inp) is pyswip.easy.Atom:
inp: pyswip.easy.Atom
return f"'{inp.value}'"
elif type(inp) is list:
inp: List
return [pyswip_output_to_str(child) for child in inp]