pyswip icon indicating copy to clipboard operation
pyswip copied to clipboard

unload_file behavior differs from prolog.

Open allComputableThings opened this issue 5 years ago • 1 comments

It seems I can use pyswip to load a .pl, but not unload one: [update]

from pyswip import Prolog
prolog = Prolog()

filename = "f"  # # f.pl contains just       foo(1,1).

next(prolog.query(filename.join(["load_files('", "',[])"])))
print(list(prolog.query("foo(X,1)")))  # ==> [{X:1}]

query = "unload_file('{}')".format(filename)
print(query)
next(prolog.query(query))

print(list(prolog.query("foo(X,1)")))  # ==> [{X:1}] -- should have failed with missing 'f'

The behavior I get from Prolog is:

?- load_files(f,[]).
true.

?- foo(X,1).
X = 1.

?- unload_file(f).    .
true.

?- foo(X,1).
ERROR: Undefined procedure: foo/2 (DWIM could not correct goal)

Is the different behavior here a bug? (I'd like to load and unload files to keep unit tests independent in Python).

allComputableThings avatar Apr 29 '20 21:04 allComputableThings

Fixed a bug in the unload step ^^ above ^^. prolog.query(unload_file('f')) still fails to unload the name foo.

allComputableThings avatar Apr 29 '20 21:04 allComputableThings