Differing semantics between multidimensional fixed-length array and slice initialization

Chris Cain clcain at uncg.edu
Wed Apr 3 11:39:44 PDT 2013


On Wednesday, 3 April 2013 at 15:56:31 UTC, Ali Çehreli wrote:
> I wonder whether it would complicate syntax? (But * already has 
> so many meanings that maybe that would not be too bad.)

I doubt it, but maybe. Plenty of languages exist that do a 
left-to-right reading of types and they seem to work out okay. 
Plus, reversing the order doesn't seem like it'd make a 
difference.

>
> > How about [5]int? It's a 5-long array of int. [5][6]int ...
> It's a 5-long
> > array of 6-long arrays of integers. And so on.
>
> [5] is already an array literal of one element. I would have to 
> be an exception to the current syntax. Still confusing...

It's no different than the current syntax from that regard. An 
type named int followed by an array literal of one element is no 
less confusing than an array literal of one element followed by a 
type named int. It has an overloaded meaning in both cases.

That said, many other languages say things like "array (0..5) of 
Integer" and such, which removes that overloaded meaning, but it 
has the problem of being a bit too verbose (IMO). It does make a 
difference if you're reading/writing many thousands of lines of 
code. Heck, even the current syntax is verbose enough to warrant 
type inference in many cases.


More information about the Digitalmars-d-learn mailing list