Hello,
thank you for your response. I don’t get some error if I put the predicate directly into swipl with
SWI-Prolog version 8.2.4 for x86_64-linux.
My prolog file simply contains the following content
:-op(803, xfy, →).
binary_connective(X → Y, X, Y).
My output in swipl is:
?- consult('logic.pl').
true.
?- binary_connective(p → q, X, Y).
X = p,
Y = q.
I also tested it on https://swish.swi-prolog.org/ and it worked exactly the same.
If I run the query from Python I don’t get some error. It seems the program stucks at some point in some endless loop.
How can I run the program from toplevel? Did you mean use:
from swiplserver import PrologServer, PrologThread
with PrologServer() as server:
with server.create_thread() as prolog_thread:
prolog_thread.query("consult('logic.pl').")
result = prolog_thread.query("binary_connective(p → q, X, Y).")
print(result)
This doesn’t work, cause of error
ImportError: cannot import name ‘PrologServer’ from ‘swiplserver’ (/home/~/.local/lib/python3.9/site-packages/swiplserver/init.py)
It seams the __init__.py
looks like this:
from swiplserver.prologmqi import (
PrologMQI,
PrologThread,
PrologError,
PrologLaunchError,
PrologQueryTimeoutError,
PrologQueryCancelledError,
PrologConnectionFailedError,
PrologResultNotAvailableError,
PrologNoQueryError,
is_prolog_variable,
is_prolog_list,
is_prolog_functor,
is_prolog_atom,
create_posix_path,
prolog_name,
prolog_args,
quote_prolog_identifier,
json_to_prolog,
)
# make "from swiplserver import *" work
__all__ = [
"PrologLaunchError",
"PrologQueryTimeoutError",
"PrologQueryCancelledError",
"PrologConnectionFailedError",
"PrologResultNotAvailableError",
"PrologNoQueryError",
"PrologError",
"PrologMQI",
"PrologThread",
"create_posix_path",
"is_prolog_functor",
"is_prolog_list",
"is_prolog_variable",
"is_prolog_atom",
"prolog_name",
"prolog_args",
"quote_prolog_identifier",
"json_to_prolog",
]