mthom / scryer-prolog

A modern Prolog implementation written mostly in Rust.
BSD 3-Clause "New" or "Revised" License
2.06k stars 122 forks source link

Tabling: Different order of predicate invocations yields different answers #1895

Open triska opened 1 year ago

triska commented 1 year ago

Trying to construct a simpler case that exhibits #1526, I came up with:

:- use_module(library(tabling)).

:- table p/1.
:- table g/1.

g(a).

p(Ls) :-
        setof(X, g(X), Ls).

Storing these definitions in tabling_problem.pl, I get:

$ scryer-prolog tabling_problem.pl
?- p(X).
   false.
?- g(X).
   X = a
;  false.

On the other hand, invoking g/1 before p/1, I get:

$ scryer-prolog tabling_problem.pl
?- g(X).
   X = a
;  false.
?- p(X).
   X = "a"
;  false.
triska commented 1 year ago

I have shortened the example, please see the updated post.