Pereira%SRI-AI@sri-unix.UUCP (10/14/83)
Consider the following code:
p(S) :- q(a,X), r(X,S).
u(S) :- r(X,S), q(a,X).
r(X,S) :- findall(Y,a(X,Y),S).
q(X,X).
a(a,1).
a(b,2).
a(a,3).
?- p(S). will return S=[2], whereas ?- u(S) will return S=[1,2,3].
This just because the two goals q and r where exchanged ! Is this
the kind of behavior one should expect from a logic programming
system ? Of course not! The problem is similar to the one of using
\+P when P has unbound variables.
In contrast, if findall is replaced by bagof in the example,
both queries will return S=[2] as they should.
-- Fernando Pereira