Re: [eclipse-clp-users] Array Access

From: Joachim Schimpf <joachim.schimpf_at_...44...>
Date: Wed, 15 Apr 2009 10:56:12 +1000
Mark Wallace wrote:
> Hi,
> I just wrote a predicate to convert a 1-dimensional array to 2D.
> 
> array2d(Row,Col,Array,Matrix) :-
>     dim(Matrix,[Row,Col]),
>     ( for(Index, 1, Row*Col), param(Col,Array,Matrix)
>       do
>           R is ((Index-1) // Col) + 1,
>           C is ((Index-1) mod Col) + 1,
>           Array[Index] #= Matrix[R,C]
>     ).
> 
> The simplest way to match the entries seems to be by using the ic solver:
> Array[Index] #= Matrix[R,C]
> but the solver itself isn't needed.
> Is there a nice  way to do this without using the ic solver?

The primitive for array element access is subscript/3, so you can rewrite
   Array[Index] #= Matrix[R,C]
in such a context as
   subscript(Array, [Index], Elem),
   subscript(Matrix, [R,C], Elem)


-- Joachim
Received on Wed Apr 15 2009 - 00:56:26 CEST

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