Hello
I wrote a script that generates “bi-dimensional” lists. I call bi-dimensional list a list like this:
{ {“a”,“b”,“c”} , {“d”,“e”,“f”} }
I associate such bi-dimensional list with a matrix like
| a d |
| b e |
| c f |
So, my bi-dimensioanl list is a 3 rows x 2 columns matrix.
The first item, {“a”,“b”,“c”}, is the first column; and the second item, {“d”,“e”,“f”}, is the second column.
So, the next script works fine:
set matrix to {{"", "", ""}, {"", "", ""}} -- set an 3x2 "empty" matrix
set item 2 of item 1 of matrix to "b"
matrix
It returns {{“”, “b”, “”}, {“”, “”, “”}}, just like I need.
But the script I wrote to generate the empty matrix generates something wrong.
After generating the “empty” matrix, setting a single element sets multiple elements.
My wrong thing is:
set rows to 2
set columns to 3
set matrix to generate_matrix(rows, columns)
set item 2 of item 1 of matrix to "b"
matrix
on generate_matrix(r, c)
set empty_vector to {{""}}
repeat c - 1 times
set empty_vector to empty_vector & {{""}}
end repeat
set empty_row to empty_vector
set empty_vector to {""}
repeat r - 1 times
set empty_vector to empty_vector & {""}
end repeat
set empty_column to empty_vector
repeat with i from 1 to c
set item i of empty_row to empty_column
end repeat
set matrix_vacia to empty_row
return matrix_vacia
end generate_matrix
generate_matrix generates {{“”, “”, “”}, {“”, “”, “”}}
But when I try to set a single value, it is “propagated” thru every matrix element, and the result is {{“”, “b”, “”}, {“”, “b”, “”}}
Well, i hope some one helps me.
Thanks in advance.