Re: How to expand a search



On Sat, 14 Apr 2007 17:51:55 -0700, RichardIII wrote:

Hi All,

I'm a Prolog nubie relying on a couple of on-line tutorial and the
documentation from SWI-Prolog, which I'm running on WinXP-Pro/SP2.

I found a simple example on the web that listed cuisine the "sam"
likes, which I expanded with what "joe" likes. The "facts" are shown
below, which are "consulted".

The queries:
12 ?- setof(Z, likes(sam, Z), Result).
13 ?- setof(Z, likes(joe, Z), Result).
14 ?- setof(Z, likes(Guy, Z), Result).
produce:
Result = [chips, pizza, spaghetti]
Result = [hero]
Guy = sam,
Result = [chips, pizza, spaghetti]

How can I embed #14 with a query that gets an array of all the Guys
and feeds them to #14 so that every Guy will be named followed by his
cuisines? Only sam gets returned in #14, no doubt because he's the
first Guy listed in the facts.

Maybe this what you want ?

?- setof(likesall(Guy,LikesAll), setof(Liked,likes(Guy,Liked),LikesAll),L).

Now L contains perhaps what you needed.


BTW, setof is a bit tricky, maybe you should stay away from it for a while.

Cheers

Bart Demoen
.



Relevant Pages

  • Re: How to expand a search
    ... Result = [chips, pizza, spaghetti] ... Only sam gets returned in #14, ...
    (comp.lang.prolog)
  • Re: How to expand a search
    ... Result = [chips, pizza, spaghetti] ... Only sam gets returned in #14, ...
    (comp.lang.prolog)
  • Re: How to expand a search
    ... I found a simple example on the web that listed cuisine the "sam" ... Result = [chips, pizza, spaghetti] ...
    (comp.lang.prolog)
  • Re: How to expand a search
    ... I found a simple example on the web that listed cuisine the "sam" ... Result = [chips, pizza, spaghetti] ...
    (comp.lang.prolog)
  • Re: How to expand a search
    ... which I'm running on WinXP-Pro/SP2. ... Result = [chips, pizza, spaghetti] ...
    (comp.lang.prolog)