Article View: comp.lang.prolog
Article #3659Re: bagof/setof
From: Richard A. O'Keefe
Date: Wed, 14 Sep 1988 00:51
Date: Wed, 14 Sep 1988 00:51
51 lines
1891 bytes
1891 bytes
In article <1436@kulcs.kulcs.uucp> bimbart@kulcs.UUCP (Bart Demoen) writes:
>database:
> p(1, a). p(_, b). p(2, c).
>query:
> ?- setof(Y,p(X,Y),L) .
>answers:
> SICSTUSprolog:
> X = 1, L = [a,b] ;
> X = 2, L = [b,c]
>
> BIMprolog:
>
> X = 1, L = [a] ;
> X = _0, L = [b] ;
> X = 2, L = [c]
>
> C Prolog:
>
> X = 1, L = [a,b] ;
> X = 2, L = [c]
>
>My question is: which is more reasonable and/or useful and/or satisfying?
Quintus Prolog:
X = _, L = [b] ;
X = 1, L = [a] ;
X = 2, L = [c]
Note that the bindings of X are enumerated in standard order (variables
precede numbers). Within each binding for X, the elements of L are in
standard order.
I am able to say that C Prolog's behaviour is a bug;
that particular result is unintended.
There are three ground solutions:
X = 1 -> L = [a,b] ;
X = 2 -> L = [b,c] ;
ground(X), X ~= 1, X ~= 2 -> L = [b]
SICStus Prolog gets two of them exactly right, but misses the third
case entirely. BIMprolog and Quintus Prolog notice that there are
three cases, and their results cover p.
What this example illustrates is that to handle "all solutions" logically
you need
- coroutining (to wait until X is sufficiently instantiated), or
- constraints (to obtain the solution X~=1, X~=2, L=[b])
As things stand, setof(Template, Generator, Set) is only defined when all
the solutions of Generator found are ground.
Technical Details
Message-ID:
<397@quintus.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!cornell!uw-beaver!teknowledge-vaxc!sri-unix!quintus!okReferences:
<1436@kulcs.kulcs.uucp>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!cornell!uw-beaver!teknowledge-vaxc!sri-unix!quintus!ok From: ok@quintus.uucp (Richard A. O'Keefe) Newsgroups: comp.lang.prolog Subject: Re: bagof/setof Message-ID: <397@quintus.UUCP> Date: 14 Sep 88 00:51:48 GMT References: <1436@kulcs.kulcs.uucp> Sender: news@quintus.UUCP Reply-To: ok@quintus.UUCP (Richard A. O'Keefe) Organization: Quintus Computer Systems, Inc. Lines: 51