PySwip PrologError with Recursion Query

58 Views Asked by At

I'm currently working on integrating SWI-Prolog with Python using the PySwip library and I've run into a problem that I can't seem to resolve on my own. I have a simple Prolog program that defines a recursive relationship, and it runs perfectly fine when I execute it directly in SWI-Prolog (?- on(a, c)). However, when I try to run the same query through PySwip, I get a PrologError related to a stack overflow.

Here's the Prolog code (test.pl):

on(a, b).
on(b, c).
on(X, Z) :- on(X, Y), on(Y, Z).

And here's the Python code using PySwip:

from pyswip import Prolog

prolog = Prolog()
prolog.consult("test.pl")
print(list(prolog.query("on(a,c)")))

When I run the Python script, I get the following error:

File "I:\Scoop\apps\miniconda3\current\envs\pyswip\Lib\site-packages\pyswip\prolog.py", line 128, in __call__
    raise PrologError("".join(["Caused by: '", query, "'. ",
pyswip.prolog.PrologError: Caused by: 'on(a,c)'. Returned: 'error(resource_error(stack), {'choicepoints': 3, 'cycle': [Functor(577933,3,11030794,:(user, on(c, _90)),[]), Functor(577933,3,11030793,:(user, on(c, _110)),[])], 'depth': 11030794, 'environments': 11030795, 'globalused': 86196, 'localused': 947959, 'stack_limit': 1048576, 'trailused': 0})'.

prolog.asserta() and prolog.assertz() seems to have the same problem.I'm not sure how to address it within the context of PySwip.

Thank you in advance for your help.

0

There are 0 best solutions below