Re: [eclipse-clp-users] instantiation fault

From: Kish Shen <kisshen_at_...5...>
Date: Wed, 08 Oct 2008 16:31:30 +0100
behemot@...78... wrote:
> Dear users!
> 
> When I run the following instructions:
> (foreach(X,[1,2,3]), foreach(Y,[4,5,6]), fromto(0,In,Out,Exp) do Out is X*Y+In).
> I get the right result i.e. 1*4+2*5+3*6=32.
> 
> I try to do the same, but using variables instead of constants in the second list.
> (foreach(X,[1,2,3]), foreach(Y,[D1,D2,D3]), fromto(0,In,Out,Exp) do Out is X*Y+In).
> Then I've got the instantiation fault. I want to get the result as follows:
> 1*D1+2*D2+3*D3.
> 
> Is there any possibility to do this in such a way ?
> 

This is quite a basic Prolog question -- you may want to read some 
introductory text on Prolog, as Wit suggested to your last question.

is/2 is a standard Prolog operator, which evaluates the right-hand side, 
which must be a ground expression (no uninstantiated variables).

Expressions are just structures, so you can build an expression with 
variables in it, which you can evaluate (e.g. with is/2) when the 
variables are all instnatied. You can build this structure by using =/2 
instead of is/2:

... do Out = X*Y+In


With constraints (supported in ECLiPSe via various constraint solver 
libraries, like ic), you can have expressions that have variables in it, 
and these act as constraints on your problem. Again, you should read 
some introductory materials on Constraint Logic Programming if you are 
interested. [the ECLiPSe-clp website has a list of suggestions at

http://www.eclipse-clp.org/reports/index.html

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 Wed Oct 08 2008 - 15:32:43 CEST

This archive was generated by hypermail 2.2.0 : Mon Jul 09 2018 - 02:05:29 CEST