Re: [eclipse-clp-users] two simple queries

From: Kish Shen <>
Date: Wed, 14 Sep 2011 22:39:50 +0100
Hi Kostas,

On 14/09/2011 21:32, Kostas Oikonomou wrote:
>     make3([r(6,[e8,e10,e19]), r(5,[e18,e15])]).
> doesn't?  The param() in make3 is not necessary, but seems
> to cause a problem.
> make3(Rs) :-
>           (foreach(r(I,Path), Rs), param(I,Path) do
>               write(I), write(' '), writeln(Path)
>           ).

The param(I,Path) is not just unnecessary, it is incorrect. The scope of 
the variables I and Path in foreach(r(I,Path) is in the loop body, and 
is a *different* variable for each iteration of the loop (you have two 
iterations in your example). Remember that in Prolog, once a variable is 
instantiated, it cannot be changed to a different value, the I and Path 
in the two iterations can take different values because they are not the 
same variables.

What param does is to pass variables from outside the loop into the 
loop, and so for such variables, they are the same variable in every 
iteration of the loop. What you are doing with param(I,Path) is that you 
are effectively trying to unify the different local variables I and Path 
in each iteration with each other, which fails.

If the values of I and Path is the same in each iteration, the 
unification will succeed, as will the query, e.g.

make3([r(6,[e8,e10,e19]), r(6,[e8,e10,e19])])

By the way, you may notice that you get singleton variable warnings for 
I and Path in make3/1, this is because these variable do not occur 
elsewhere outside the loop in make3/1.

In general, as long as you use _ to start names of intentionally 
singleton variables, then singleton variable warning is always a sign 
that something is wrong, and you should not ignore it. Fix it 
immediately. When I first started programming in Prolog, I often ignored 
singleton variable warnings, until I spent a lot of time debugging my 
programs and discovered the problem was due to mispelling of variables 
names that I was told about in the singleton variable warnings.



This e-mail may contain confidential and privileged material for the
sole use of the intended recipient. Any review, use, distribution or
disclosure by others is strictly prohibited. If you are not the intended
recipient (or authorized to receive for the recipient), please contact
the sender by reply e-mail and delete all copies of this message.
Cisco Systems Limited (Company Number: 02558939), is registered in
England and Wales with its registered office at 1 Callaghan Square,
Cardiff, South Glamorgan CF10 5BT.
Received on Wed Sep 14 2011 - 21:39:56 CEST

This archive was generated by hypermail 2.2.0 : Thu Feb 02 2012 - 02:31:58 CET