I successfully did some Prolog from Python examples but failed on this one:
import janus_swi as janus
janus.consult("get", """
:- use_module(library(lists)).
frame(name(bird), isa(animal), [travel(flies), feathers], [ ]).
frame(name(penguin), isa(bird), [color(brown)], [travel(walks)]).
frame(name(canary), isa(bird), [color(yellow), call(sing)], [size(small)]).
frame(name(tweety), isa(canary), [ ], [color(white)]).
frame(name(opus), isa([penguin, cartoon_char]), [color(black)], [ ]).
get(Prop, Object) :- frame(name(Object), _, List_of_properties, _), member(Prop, List_of_properties).
get(Prop, Object) :- frame(name(Object), _, _, List_of_defaults), member(Prop, List_of_defaults).
get(Prop, Object) :- frame(name(Object), isa(Parent), _, _), get(Prop, Parent).
""")
q = janus.query("get(X, penguin).")
while ( s := q.next() ):
print(s['X'])
q.close()
I expected as output:
X = color(brown) ;
X = travel(walks) ;
X = travel(flies) ;
X = feathers ;
false.
But instead received following error:
Traceback (most recent call last):
File "C:\Users\marti\OneDrive\Documents\Python\Swi-Prolog.py", line 19, in <module>
while ( s := q.next() ):
File "C:\Users\marti\AppData\Local\Programs\Python\Python310\lib\site-packages\janus_swi\janus.py", line 215, in next
rc = _swipl.next_solution(self.state)
SystemError: <built-in function next_solution> returned NULL without setting an exception
Please help ! My Swi-Prolog is 64 bits, version 9.2.2
I am on Windows 11 64 bit with Python 3.10.6 64 bit
Regards Martin Klein