Question: How do I duplicate complex arrays?

March 26 2014 bastorer 10
Maple 17

1

Hello,

As a means of encoding information, I'm working with nested array objects (I had originally used lists, but they became too large and Maple suggested that I use arrays). The nesting should be at most four deep, but the nested arrays can have varying lengths. In order to work with the arrays, I have a series of procedures that manipulate a given array and update the existing array object to contain the result. The issue that I have is that one of my procedures needs to simultaneously use both the original array and a modified version of the array, but once the modification is performed, the original version no longer exists.

Ultimately, my issue boils down to this: is there a clean (or messy, I'm not picky) way to duplicate an array so that there are two copies of the array in memory? Just writting Array2 := Array1 just creates another pointer to the same array in memory from what I can tell, so that doesn't work. There is a function copy, but it doesn't seem to work on nested arrays. 

For example, running the following does not modify Array2.

Array1 := Array([Array([1, 2]), Array([3, 4])]);
Array2 := Array([Array([1, 2]), Array([5, 6])]);
copy(Array1, Array2);

Indeed, neither does

Array1 := Array([Array([1, 2]), Array([3, 4])]);
Array2 := Array([Array([1, 2]), Array([5, 6])]);
copy(Array1(2), Array2(2));

Unfortunately, the latter case would seem to mean that I can't just write a procedure to recurse through my layers of arrays and copy piecewise either.

Thanks in advance for any help.

Please Wait...