Thread overview | |||||
---|---|---|---|---|---|
|
February 07, 2006 Question and answer | ||||
---|---|---|---|---|
| ||||
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? |
February 07, 2006 Re: Question and answer | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ivan Senji | 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). |
February 07, 2006 Re: Question and answer | ||||
---|---|---|---|---|
| ||||
Posted in reply to Don Clugston | 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.
|
Copyright © 1999-2021 by the D Language Foundation