From ok@atlas.otago.ac.nz Thu Feb 15 23:38:29 2001
Received: from atlas.otago.ac.nz (atlas.otago.ac.nz [139.80.32.250])
	by swi.psy.uva.nl (8.11.2/8.11.2) with ESMTP id f1FMcRZ20003
	for <prolog@swi.psy.uva.nl>; Thu, 15 Feb 2001 23:38:28 +0100 (MET)
Received: (from ok@localhost)
	by atlas.otago.ac.nz (8.9.3/8.9.3) id LAA14711;
	Fri, 16 Feb 2001 11:38:18 +1300 (NZDT)
Date: Fri, 16 Feb 2001 11:38:18 +1300 (NZDT)
From: "Richard A. O'Keefe" <ok@atlas.otago.ac.nz>
Message-Id: <200102152238.LAA14711@atlas.otago.ac.nz>
To: 50000481@plink.cityu.edu.hk, prolog@swi.psy.uva.nl
Subject: Re:  [SWIPL] using bagof

Cecilia Wong <50000481@plink.cityu.edu.hk> 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.


