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

Problem in representing incomplete structures #157

Open remuspetrache opened 4 months ago

remuspetrache commented 4 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)?