Re: [eclipse-users] List --> Row

From: Marco Gavanelli <marco.gavanelli_at_unife.it>
Date: Mon, 03 Dec 2007 16:14:15 +0100
Tom Schulte wrote:
> Question: How could one take a List datatype and insert into as a column or row in a 2-D Array (Matrix)>
> 
> Thank you, any help is appreciated

A 2D Matrix in ECLiPSe can be:
- a list of lists, as in the library matrix_util
- a term of terms, as you can define it with the dim/2 predicate.

In the first case, you can insert a row with operations on lists:

[eclipse 1]: lib(matrix_util).
matrix_util.eco loaded traceable 0 bytes in 0.01 seconds
[eclipse 2]: matrix(3,2,Rows), L=[1,2], Rows=[_,L,_].

Rows = [[_293, _295], [1, 2], [_305, _307]]
L = [1, 2]
Yes (0.00s cpu)

In the second case, you can insert a row with operations on terms:

[eclipse 3]: dim(A,[3,2]), L=[1,2], arg(2,A,Row), Row =.. [_|L].

A = []([](_339, _340), [](1, 2), [](_333, _334))
L = [1, 2]
Row = [](1, 2)
Yes (0.00s cpu)

The second should be more efficient, as you are representing the matrix 
as an array (as you would do in C).
To insert a column, you can first transpose the matrix, and then insert 
a row.

Best,
Marco
-- 
Marco Gavanelli, Ph.D.
Computer Science Division
Dipartimento di Ingegneria
University of Ferrara
Via Saragat 1 - 44100 Ferrara (Italy)
Tel  +39-0532-97-4833
Fax  +39-0532-97-4870
http://www.ing.unife.it/docenti/MarcoGavanelli/
Received on Mon Dec 03 2007 - 15:14:23 CET

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