Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Too many stacked strings

83 views
Skip to first unread message

SymonJory

unread,
May 26, 2021, 9:07:51 AM5/26/21
to pyswip

Hi,

I'm running the following code:
from pyswip import *
prolog = Prolog()
prolog.assertz("smokes(j)")
prolog.assertz("smokes(b)")
prolog.assertz("friends(j,b)")
prolog.assertz("friends(b,j)")
prolog.assertz("cancer(X) :- smokes(X)")
prolog.assertz("smokes(Y) :- friends(X,Y), smokes(X)")
q = prolog.query("smokes(Z)")
print(list(q))

This returns the error "Too many stacked strings". I'm sure there is an obvious problem with my code, but I don't see what the problem in my code is. I'd benefit from any trouble-shooting.

best,
Symon

SymonJory

unread,
May 26, 2021, 11:48:16 AM5/26/21
to pyswip
I believe this is due to looping. It could be solved by reference to swipl's "distinct". Does pyswip have a version of "distinct"?

SymonJory

unread,
May 26, 2021, 11:51:02 AM5/26/21
to pyswip
Solved the problem. For others who want to avoid this, the following code should run fine:

from pyswip import *
prolog = Prolog()
prolog.assertz("smokes(j)")
prolog.assertz("smokes(b)")
prolog.assertz("friends(j,b)")
prolog.assertz("friends(b,j)")
prolog.assertz("cancer(X) :- smokes(X)")
prolog.assertz("distinct(smokes(Y) :- friends(X,Y), smokes(X))")

q = prolog.query("smokes(Z)")
print(list(q))
Reply all
Reply to author
Forward
0 new messages