Re: [eclipse-clp-users] Array Dimension

From: Kish Shen <kisshen_at_...5...>
Date: Wed, 28 Oct 2009 01:22:54 +0000
Igor Kondrasovas wrote:

> I have a simple question regarding array dimension. I must create a
> 2-dimension array based on the size of two 1-dimension arrays. For instance:
> 
>  
> 
> I have a predicate like:
> 
>  
> 
> Linear(pieces, bars):- % pieces and bars are 1 dimensional arrays (from any
> length). Then I must create a 2 dimension array based on its size:
> 
>  
> 
> dim(M,[pieces length, bars length]),
> 
>  

I assume you know that the syntax you are showing (with predicate name 
Linear and variable names pieces and bars) are not correct 
ECLiPSe/Prolog syntax: predicate names should start with a small letter, 
and variable names should start with a capital letter.

As the User Manual says in the section on Array Notation (in the 
ECLiPSee-specific Language Feature chapter):

 >To create multi-dimensional arrays conveniently, the built-in dim/2 is 
 >provided (it can also be used backwards to access the array dimensions)

so you can use dim/2 to get the dimensions of the pieces and bars:

linear(Pieces, Bars) :-
    dim(Pieces, [PSize]), % get size of Pieces
    dim(Bars, [BSize]),   % get size of Bars
    dim(M, [PSize, BSize]), % create new matrix M
    ...

This assumes (as you stated) that Pieces and Bars are one dimensional 
arrays (i.e. structures) when you call linear/2.

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 28 2009 - 01:49:06 CET

This archive was generated by hypermail 2.3.0 : Tue Apr 16 2024 - 09:13:20 CEST