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

From: Kish Shen <kisshen_at_...5...>
Date: Mon, 03 Dec 2007 23:26:34 +0000
Kish Shen wrote:
> set_col(Col, N, M) :-   % set the column N of matrix M to the values in Col
>     (foreacharg(Row, M), foreacharg(E, Col), param(N) do
>        arg(N, Row, E)
>     )
I forgot to consider Tom's original question of using a list and 
inserting that. The above code uses an array.
A list can be used with the following code:

set_col(Col, N, M) :-
    (foreacharg(Row, M), foreach(E, Col), param(N) do
       arg(N, Row, E)
    )

[eclipse 19]: dim(M, [3,4]), set_col([1,2,3], 2, M).

M = []([](_277, 1, _279, _280), [](_272, 2, _274, _275), [](_267, 3, 
_269, _270))
Yes (0.00s cpu)

Note that the list must have the correct length, matching that of the 
number of rows (3 in this case). Otherwise the predicate will either 
fail or abort with an out of range error.

Cheers,

Kish
Received on Mon Dec 03 2007 - 23:26:46 CET

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