bug-prolog
[Top][All Lists]
Advanced

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

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


From: Dave Sworin
Subject: Is a singleton the same as a free variable in setof/3?
Date: Wed, 2 Jul 2008 16:00:12 -0700 (PDT)

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]