Re: [eclipse-clp-users] Constraints in Loop

From: Kish Shen <kisshen_at_...5...>
Date: Thu, 29 Oct 2009 18:15:16 +0000
Igor Kondrasovas wrote:
> 
>       (for(I,1,NPieces) do
> 
>             M[I,1] + M[I,2] + M[I,3] #= 1),

Your problem is a common error with using the do loops, which is an 
ECLiPSe extension to Prolog. The scope rule for variables inside do 
loops is perhaps unusual: the scope does not extend into the body of a 
do loop, so the M inside the loop is different from the M outside. You 
need to pass M in as a parameter:

     (for(I,1,NPieces), param(M) do

The reason you don't get an error when you use =/2 instead of #=/2 is
not because the correct variable is accessed, but simply because you are 
performing a simple unification, which is fine with the uninstantiated 
variable M inside the loop -- it is still not the same M as outside. (In 
your specific case, the unification should be failing, because the two 
sides of the = will not unify).

Cheers,

Kish
-- 
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 Thu Oct 29 2009 - 18:15:42 CET

This archive was generated by hypermail 2.3.0 : Wed Sep 25 2024 - 15:13:20 CEST