Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!decvax!tektronix!ogcvax!omsvax!icalqa!hplabs!sri-unix!Pereira@SRI-AI From: Pereira%SRI-AI@sri-unix.UUCP Newsgroups: net.lang.prolog Subject: More on findall Vs. bagof Message-ID: <12709@sri-arpa.UUCP> Date: Fri, 14-Oct-83 11:26:56 EDT Article-I.D.: sri-arpa.12709 Posted: Fri Oct 14 11:26:56 1983 Date-Received: Sun, 23-Oct-83 04:06:07 EDT Lines: 23 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