Subject: Re: [SWIPL] using bagof

From: "Richard A. O'Keefe" <[email-masked]>
Date: Fri, 16 Feb 2001 11:38:18 +1300 (NZDT)

Cecilia Wong <[email-masked]> wrote:
	I have the following codes,
	
	proclist([],[]).
	proclist([H|Rest], [HP|RestP]):-
	 bagof([H, R, M], satall(H, R, M), LOL),
	 cons(LOL, LOLC).
	
I am puzzled by this.
Why does nothing determine a value for RestP?
What does cons/2 do?
Why does nothing use LOLC?

I wonder why you are using a list?  Are H, R, and M all of exactly the
same abstract type?  If they are not, a list is not appropriate.

	However, in some cases, the "LOL" will contain nothing.  I hope
	that even nothing is returned in LOL, it should still flow the
	empty list to the procedure,

It is time to actually READ the fine manual, or any good Prolog textbook.

It is an absolutely ESSENTIAL feature of bagof/3 and setof/3 that they
must never ever *EVER* return an empty bag or set.  Never!  If they could
do that, then nested use of them wouldn't work.  Returning the empty
list would be a way of doing negation, and that would in general be
unsound.

The quick fix to your code is to use findall/3, which DOES return
an empty list, but does NOT work logically the way bagof/3 must.