bug-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is a singleton the same as a free variable in setof/3?


From: Dave Sworin
Subject: Re: Is a singleton the same as a free variable in setof/3?
Date: Thu, 17 Jul 2008 23:48:17 -0700 (PDT)

I tested the same Prolog queries in SWI Prolog and got the same result as in GNU Prolog so I think I need to better understand how setof/3 works.  I apologize if I caused you unnecessary effort.

 

Dave

--- On Wed, 7/2/08, Dave Sworin <address@hidden> wrote:

From: Dave Sworin <address@hidden>
Subject: Is a singleton the same as a free variable in setof/3?
To: address@hidden
Date: Wednesday, July 2, 2008, 4:00 PM

Hello,

 

   I got an unexpected result with setof/3.  However, I'm not sure this is a problem or not.  So I reproduced the behavior by repeating the setof/3 example found in Prolog: The Standard, Reference Manual, by Deransart, Ed-Dbali, and Cervoni, from Springer, 1996, page161.  The example works exactly as described, but when I add another parameter to the legs/2 predicate so it becomes legs/3, but pass a singleton for the new argument, I get a result I didn't expect and it is the same result as if I used a variable instead of the singleton.  See the trace from gprolog below.  I was running this on an old P3 with Fedora Core 2.  See below.

 

Dave

 

address@hidden ceg]$ gprolog
GNU Prolog 1.3.0
By Daniel Diaz
Copyright (C) 1999-2007 Daniel Diaz
| ?- ['utilities.pl'].
compiling /home/daves/.../utilities.pl for byte code...
/home/daves/.../utilities.pl compiled, 35393 lines read - 1650651 bytes written, 2729 ms
 
(629 ms) yes
| ?- assertz((legs(A,6):-insect(A))).
 
yes
| ?- assertz((legs(A,4):-animal(A))).
 
yes
| ?- assertz((legs(A,8):-spider(A))).
 
yes
| ?- assertz((insect(bee))).
 
yes
| ?- assertz((insect(ant))).
 
yes
| ?- assertz((animal(horse))).
 
yes
| ?- assertz((animal(cat))).
 
yes
| ?- assertz((animal(dog))).
 
yes
| ?- assertz((spider(tarantula))).
 
yes
| ?- setof(A,legs(A,N),B).
 
B = [cat,dog,horse]
N = 4 ? ;
 
B = [ant,bee]
N = 6 ? ;
 
B = [tarantula]
N = 8
 
(1 ms) yes
| ?- assertz((legs(A,'abc',6):-insect(A))).
 
yes
| ?- assertz((legs(A,'def',4):-animal(A))).
 
yes
| ?- assertz((legs(A,'ghi',8):-spider(A))).
 
yes
| ?- setof(A,legs(A,_,N),B).
 
B = [ant,bee]
N = 6 ? ;
 
B = [cat,dog,horse]
N = 4 ? ;
 
B = [tarantula]
N = 8
 
(1 ms) yes
| ?- assertz((legs(A,8):-octopus(A))).
 
yes
| ?- assertz((octopus(tarantula))).
 
yes
| ?- setof(A,legs(A,N),B).
 
B = [cat,dog,horse]
N = 4 ? ;
 
B = [ant,bee]
N = 6 ? ;
 
B = [tarantula]
N = 8

(1 ms) yes
| ?- assertz((legs(A,'jkl',8):-spider(A))).

yes
| ?- setof(A,legs(A,_,N),B).

B = [ant,bee]
N = 6 ? ;

B = [cat,dog,horse]
N = 4 ? ;

B = [tarantula]
N = 8 ? ;

B = [tarantula]
N = 8

(1 ms) yes
| ?- setof(A,legs(A,C,N),B).

B = [ant,bee]
C = abc
N = 6 ? ;

B = [cat,dog,horse]
C = def
N = 4 ? ;

B = [tarantula]
C = ghi
N = 8 ? ;
 
B = [tarantula]
C = jkl
N = 8
 
yes
| ?-

 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]