yuce / pyswip

PySwip is a Python-Prolog interface that enables querying SWI-Prolog in your Python programs.
https://pyswip.org
MIT License
482 stars 98 forks source link

Problem in representing incomplete structures #157

Open remuspetrache opened 7 months ago

remuspetrache commented 7 months ago

I am currently using the latest version of Pyswip and I have a problem in getting the correct representation of incomplete structures. For example, in Prolog an incomplete list would look like: L = [1,2,3 | _].

My code:

prolog = Prolog()
query_string = "L=[1,2,3,_|_]"
results = list(prolog.query(query_string))
    for result in results:
            print(result)

The result is: {'L': [1, 2, 3, Variable(77)]}

If I use LS = [1,2,3 | LE], LE = [4,5 | _] I get {'LS': [1, 2, 3, 4, 5], 'LE': [4, 5]}

I understand that it is quite complicated to translate such structures directly into a Python list, but I was wondering what alternatives are there. How could I get the incomplete structure representation (maybe as a string instead of a list)?