B
Boris
Been looking this up in the myriad of deepcopy strands, but couldn't
find it in 30 minutes, so I'm posting the question.
The question is simple. What way would you create an array that
contains 5 copies of an array, without the copies interfering with each
other?
array = [1,2,3]*5
generates:
[[1,2,3],[1,2,3],[1,2,3],[1,2,3],[1,2,3]]
but unfortunately also makes 'array[1][1] = "a"' change it like this:
[[1,"a",3],[1,"a",3],[1,"a",3],[1,"a",3],[1,"a",3]]
---------
Anyway, found a solution during tinkering, although I don't know why.
Thought I'd just still post it anyway.
ar = []
5.times{ar << [1,2,3]}
works, and 'array[1][1] = "a"' results in the thing I want
[[1,2,3],[1,"a",3],[1,2,3],[1,2,3],[1,2,3]]
find it in 30 minutes, so I'm posting the question.
The question is simple. What way would you create an array that
contains 5 copies of an array, without the copies interfering with each
other?
array = [1,2,3]*5
generates:
[[1,2,3],[1,2,3],[1,2,3],[1,2,3],[1,2,3]]
but unfortunately also makes 'array[1][1] = "a"' change it like this:
[[1,"a",3],[1,"a",3],[1,"a",3],[1,"a",3],[1,"a",3]]
---------
Anyway, found a solution during tinkering, although I don't know why.
Thought I'd just still post it anyway.
ar = []
5.times{ar << [1,2,3]}
works, and 'array[1][1] = "a"' results in the thing I want
[[1,2,3],[1,"a",3],[1,2,3],[1,2,3],[1,2,3]]