yuce / pyswip

PySwip is a Python - SWI-Prolog bridge enabling to query SWI-Prolog in your Python programs. It features an (incomplete) SWI-Prolog foreign language interface, a utility class that makes it easy querying with Prolog and also a Pythonic interface.
MIT License
464 stars 97 forks source link

Error by using char '¬' as operator in prolog and translate it with pyswip #139

Open Losbarthos opened 2 years ago

Losbarthos commented 2 years ago

For some reason the char '¬' used as operator in a prolog file leads to an error in pyswip.

Python-file:

 from pyswip import Prolog

prolog = Prolog()

prolog.consult("test.pl")

for res in prolog.query(f"m_Proposition_Binary_x_y(∨(¬(p), q), A, B)."):
    print(res)

Prolog-file ("test.pl")

:-op(800, fx, ¬).
:-op(802, xfy, ∨).

m_Proposition_Binary_x_y(X ∨ Y, X, Y).

Error-Message:

Traceback (most recent call last):
  File "~/test.py", line 43, in <module>
    for res in prolog.query(f"m_Proposition_Binary_x_y(∨(¬(p), q), A, B)."):
  File "/home/martin/.local/lib/python3.9/site-packages/pyswip/prolog.py", line 112, in __call__
    t = getTerm(swipl_list)
  File "/home/martin/.local/lib/python3.9/site-packages/pyswip/easy.py", line 436, in getTerm
    res = getList(t)
  File "/home/martin/.local/lib/python3.9/site-packages/pyswip/easy.py", line 451, in getList
    result.append(getTerm(head))
  File "/home/martin/.local/lib/python3.9/site-packages/pyswip/easy.py", line 438, in getTerm
    res = getFunctor(t)
  File "/home/martin/.local/lib/python3.9/site-packages/pyswip/easy.py", line 460, in getFunctor
    return Functor.fromTerm(t)
  File "/home/martin/.local/lib/python3.9/site-packages/pyswip/easy.py", line 291, in fromTerm
    args.append(getTerm(a0 + i))
  File "/home/martin/.local/lib/python3.9/site-packages/pyswip/easy.py", line 438, in getTerm
    res = getFunctor(t)
  File "/home/martin/.local/lib/python3.9/site-packages/pyswip/easy.py", line 460, in getFunctor
    return Functor.fromTerm(t)
  File "/home/martin/.local/lib/python3.9/site-packages/pyswip/easy.py", line 293, in fromTerm
    return cls(f.value, args=args, a0=a0)
  File "/home/martin/.local/lib/python3.9/site-packages/pyswip/easy.py", line 267, in __init__
    self.name = Atom(PL_functor_name(self.handle))
  File "/home/martin/.local/lib/python3.9/site-packages/pyswip/easy.py", line 68, in __init__
    self.chars = PL_atom_wchars(self.handle, byref(slen))
ValueError: character U+ffffffac is not in range [U+0000; U+10ffff]

For some reason '¬' (has unicode U+00AC) is translated into U+ffffffac. Can you reproduce this error/bug?

If I replace '¬' (in prolog and python-file) by some other char, say '~' or '∧' everything works fine and gives: {'A': '∧(p)', 'B': 'q'} or {'A': '~(p)', 'B': 'q'}

Version used 0.2.11