how to use unknown size of array at compile time for further processing

thorstein torsten.lange at mail.de
Sun Oct 1 14:23:54 UTC 2017


> Guyes, I obviously made a mistake. Forget my post!

Sorry, I'm still really confused with the results from my 
function:

double[][] transp(double[][] array)
{

   double[][] arrayT;
   double[] rowT;
   // initialize rowT
   foreach(i; 0..array.length)
   {
     rowT ~= 0;
   }

   foreach(col; 0..array[0].length-3)
   {
     foreach(row; 0..array.length)
     {
       rowT[row] = array[row][col];
     }
     writeln("rowT 1: ",rowT);
     writeln("arrayT 1: ", arrayT);
     arrayT ~= rowT;
     writeln("rowT 2: ",rowT);
     writeln("arrayT 2: ", arrayT,"\n");
   }
     return arrayT;
}

Again, assuming my original array to be:
   array =
     [
       [ 4,  3,   1,   5,  2],
       [19, 34,  23, 100, 59],
       [62,  1,   4,   0, 76],
       [23,  6, 989,  98,  1],
       [ 5, 87,  45,  62,  9],
       [ 5, 87,  45,  62,  9]
     ];

... the results are strange. Before the appending (arrayT ~= 
rowT;) happens for the second column of array arrayT was 
miraculous modified:

rowT 1: [4, 19, 62, 23, 5, 5]
arrayT 1: []
rowT 2: [4, 19, 62, 23, 5, 5]
arrayT 2: [[4, 19, 62, 23, 5, 5]]

rowT 1: [3, 34, 1, 6, 87, 87]
arrayT 1: [[3, 34, 1, 6, 87, 87]]
rowT 2: [3, 34, 1, 6, 87, 87]
arrayT 2: [[3, 34, 1, 6, 87, 87], [3, 34, 1, 6, 87, 87]]

etc...

Is there any linkage between rowT and arrayT????

Thanks again!


More information about the Digitalmars-d-learn mailing list