One case of array assignments

John Colvin john.loughran.colvin at gmail.com
Wed Mar 13 14:20:53 PDT 2013


On Wednesday, 13 March 2013 at 21:07:18 UTC, H. S. Teoh wrote:
> On Wed, Mar 13, 2013 at 09:59:33PM +0100, John Colvin wrote:
>> On Wednesday, 13 March 2013 at 20:46:35 UTC, Timon Gehr wrote:
> [...]
>> >Then what's the meaning of
>> >
>> >int[3][3] x = [1,2,3];
>> >
>> >Is it
>> >
>> >int[3][3] x = [[1,2,3],[1,2,3],[1,2,3]];
>> >
>> >or
>> >
>> >int[3][3] x = [[1,1,1],[2,2,2],[3,3,3]];
>> 
>> the former, clearly. It directly follows from
>> 
>> int[3] a = 1;
>> 
>> Every element of the array is initialised to the value given. 
>> x is
>> an array of arrays and hence each "element-array" is 
>> initialised to
>> the array on the right hand side.
>
> I don't like this. It adds a lot of parsing complexities just 
> for some
> syntactic sugar with no clear benefits beyond being easier to 
> type. Why
> not just use the existing array operations syntax?
>
> 	int[3] a;
> 	a[] = 1;	// makes intent clear
>
> 	int[3][3] b;
> 	b[] = [1, 2, 3]; // fits into current syntax already
>
>
> T

This is supposed to be static initialisation, which is different, 
no?


More information about the Digitalmars-d mailing list