Menu
Search
```H. S. Teoh:

> Wait, really? Benjamin Franklin? I thought it was a quote I snitched
> from Slashdot:

I have adapted it, it's not a true quotation :-)

Bye,
bearophile
```
```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

--
Today's society is one of specialization: as you grow, you learn more and more about less and less. Eventually, you know everything about nothing.
```
```On Wed, Mar 13, 2013 at 10:03:23PM +0100, bearophile wrote:
> H. S. Teoh:
>
> >Wait, really? Benjamin Franklin? I thought it was a quote I snitched from Slashdot:
>
> I have adapted it, it's not a true quotation :-)
[...]

Sure, but why Benjamin Franklin, though? (As opposed to anybody else.) Was he really the one who came up with the original expression?

T

--
There are three kinds of people in the world: those who can count, and those who can't.
```
```On 03/13/2013 09:59 PM, John Colvin wrote:
> On Wednesday, 13 March 2013 at 20:46:35 UTC, Timon Gehr wrote:
>> On 03/13/2013 09:23 PM, John Colvin wrote:
>>> On Wednesday, 13 March 2013 at 20:10:14 UTC, bearophile wrote:
>>>>> int[10][3] = [1, 2, 3];
>>>>
>>>> Currently that second line of code doesn't work.
>>>>
>>>> Bye,
>>>> bearophile
>>>
>>> It would be really nice if it did.
>>
>> 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.

That's clearly a valid way of reasoning, however, it is not the only one.

int[3] a = 1;
int[3] b = 2;
int[3] c = 3;

int[3][3] x = [a,b,c];
```
```H. S. Teoh:

> Sure, but why Benjamin Franklin, though?

Because I have adapted one of the phrases attributed to him:

http://en.wikiquote.org/wiki/Benjamin_Franklin

Bye,
bearophile
```
```On Wednesday, 13 March 2013 at 21:08:30 UTC, Timon Gehr wrote:
> On 03/13/2013 09:59 PM, John Colvin wrote:
>> On Wednesday, 13 March 2013 at 20:46:35 UTC, Timon Gehr wrote:
>>> On 03/13/2013 09:23 PM, John Colvin wrote:
>>>> On Wednesday, 13 March 2013 at 20:10:14 UTC, bearophile wrote:
>>>>>> int[10][3] = [1, 2, 3];
>>>>>
>>>>> Currently that second line of code doesn't work.
>>>>>
>>>>> Bye,
>>>>> bearophile
>>>>
>>>> It would be really nice if it did.
>>>
>>> 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.
>
> That's clearly a valid way of reasoning, however, it is not the only one.
>
> int[3] a = 1;
> int[3] b = 2;
> int[3] c = 3;
>
> int[3][3] x = [a,b,c];

this would also be valid, as you have fully specified the elements of the array. I don't see the conflict?
```
```One consequence of the current syntax (this is another combo), this is accepted:

int[1][3] a = [[1] [0], [2]];
void main() {}

Bye,
bearophile
```
```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?
```
```On Wed, Mar 13, 2013 at 10:20:53PM +0100, John Colvin wrote:
> 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
[...]
> This is supposed to be static initialisation, which is different, no?

Hmm. In that case, what about a syntax adapted from the current array ops?

int[3] a[] = 1;

But the problem is that it's ambiguous with the current specs that interprets this as int[3][] a = 1.

Why is it bad to have to explicitly list the elements for static initialization?

T

--
Real Programmers use "cat > a.out".
```
```On Wednesday, 13 March 2013 at 21:33:47 UTC, H. S. Teoh wrote:
> On Wed, Mar 13, 2013 at 10:20:53PM +0100, John Colvin wrote:
>> 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
> [...]
>> This is supposed to be static initialisation, which is different,
>> no?
>
> Hmm. In that case, what about a syntax adapted from the current array
> ops?
>
> 	int[3] a[] = 1;
>
> But the problem is that it's ambiguous with the current specs that
> interprets this as int[3][] a = 1.
>
> Why is it bad to have to explicitly list the elements for static
> initialization?
>
>
> T

I would be great if we could get rid of post-fix array declarations for good, but I'm not sure how realistic that is.

It's bad to have to explicitly list them because there could be hundreds, thousands or even millions of elements.
```
1 2 3 4