To call prolog programs in python there is the libary pyswip.
Is there a possibility to get information if a rule for a given value is true or false. If I call a fact in console from swipl I get e.g.
?- dad(a). true.
If I try the same in python with:
from pyswip import Prolog, registerForeign
from pyswip import Prolog
prolog = Prolog()
prolog.assertz("dad(peter)")
for res in prolog.query("dad(peter)."):
print(res)
It gives me only the output:
{}
and not True. Is there another function I can call to get True or False at this point or is the expected value of the query function in that case {}?
>Solution :
From Prolog’s point of view, {} is the expected result. When a Prolog query succeeds, Prolog prints a set of answer substitutions:
?- dad(X).
X = peter.
As a special case, if no variables from the query are bound, Prolog needs to indicate that (a) the query succeeded, and that (b) no variables were bound. Traditionally, this is done by printing something like yes or true. But this is just a shorthand for "success, and there were zero substitutions". And it’s only a printing convention, not a "return value" in any real sense. Prolog has no return values.
If you use a foreign library that represents success-and-a-set-of-answer-substitutions using the language’s set type, then it makes sense that success-and-zero-substitutions is represented as a zero-element set, i.e., {}.