digitalmars.D - Question and answer
- Ivan Senji (37/37) Feb 07 2006 Here i will ask a question, and then answer it the way I think Walter
- Don Clugston (5/57) Feb 07 2006 I think so. Read
- Ivan Senji (5/9) Feb 07 2006 I remember that proposal but it was very long time ago, and it gave hope...
Here i will ask a question, and then answer it the way I think Walter would answer. I would like to create a dynamic but rectangular array (example not D syntax): <example1> int[,,,,] array = new int[10,7,5,3,2]; array[x,y,z,w,t] = 100; </example1> Question: how or when will this be available in D? Answer: But you can already to the same thing in D, just write: <example2> int[][][][][] array = new int[][][][10]; for(int i=0; i<10; i++) { array[i].length = 7; for(int j=0; j<7; j++) { array[i][j].length = 5; for(int k=0; k<5; k++) { array[i][j][k].length = 3; for(int l=0; l<3; l++) { array[i][j][k][l].length = 2; } } } } and then: array[x+y*10+z*10*7+w*10*7*5+t*10*7*5*3] = 100; //maybe correct </example2> Although i agree that the code in these two examples looks almost identical and can hardly imagine why anyone would wan't to write the first one :) , there may be people who think the first is just a little bit simpler. Is something like this even a remote posibillity for 2.0 D?
Feb 07 2006
Ivan Senji wrote:Here i will ask a question, and then answer it the way I think Walter would answer. I would like to create a dynamic but rectangular array (example not D syntax): <example1> int[,,,,] array = new int[10,7,5,3,2]; array[x,y,z,w,t] = 100; </example1> Question: how or when will this be available in D? Answer: But you can already to the same thing in D, just write: <example2> int[][][][][] array = new int[][][][10]; for(int i=0; i<10; i++) { array[i].length = 7; for(int j=0; j<7; j++) { array[i][j].length = 5; for(int k=0; k<5; k++) { array[i][j][k].length = 3; for(int l=0; l<3; l++) { array[i][j][k][l].length = 2; } } } } and then: array[x+y*10+z*10*7+w*10*7*5+t*10*7*5*3] = 100; //maybe correct </example2> Although i agree that the code in these two examples looks almost identical and can hardly imagine why anyone would wan't to write the first one :) , there may be people who think the first is just a little bit simpler. Is something like this even a remote posibillity for 2.0 D?I think so. Read http://homepages.uni-regensburg.de/~nen10015/documents/D-multidimarray.html Walter said it was a good proposal. It will definitely not be in 1.0 (even array operations, which are in the spec, will not be in 1.0 AFAIK).
Feb 07 2006
Don Clugston wrote:I think so. Read http://homepages.uni-regensburg.de/~nen10015/documents/D-multidimarray.html Walter said it was a good proposal. It will definitely not be in 1.0 (even array operations, which are in the spec, will not be in 1.0 AFAIK).I remember that proposal but it was very long time ago, and it gave hope that something will happen, but I think that this is as important as implicit template instantiation, especialy for a language that has a lot of potential to handle arrays better than most other languages.
Feb 07 2006