[eclipse-clp-users] How to use custom functions in searches

From: Sergey Dymchenko <kit1980_at_gmail.com>
Date: Fri, 27 May 2011 01:06:56 +0300

I'm very new to Prolog and ECLiPSe.

I can't understand how to use custom functions in searches.

For example, I have a list A and I want to find all variants of list B
such that maximum elements in vector product A*B is not greater than
The code I wrote:

:- lib(ic).

max_vector_product(L1, L2, R) :-
        (foreach(E1, L1),
         foreach(E2, L2),
         foreach(Product, Product_list)
        Product is E1 * E2
        R #= max(Product_list).

solve :-
        A = [7, 8, 1],

        length(A, N),
        length(B, N),
        B :: 0..3,
        max_vector_product(A, B) #=< 20,

But I get an error with the code: instantiation fault in *(7,
_135682{0 .. 3}, _135754)
How to deal with that?

And the code works, for example, if I just want to limit maximum of B to 2 -
max(B) #=< 2,
but not with my custom function (and the custom function works on its own).
Received on Thu May 26 2011 - 22:07:02 CEST

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