Proposal: struct and array literal syntax
Stewart Gordon
smjg_1998 at yahoo.com
Mon Jun 26 05:49:21 PDT 2006
Boris Wang wrote:
<snip>
> May be:
>
> int[][]![
> ![1,2,3,4],
> ![5,6,7,8],
> ![9,0,1,2],
> ![3,4,5,6],
> ]
>
> the type of ![1,2,3,4] can be inferred.
To me, using '!' in the prefix position like this is just asking for
confusion (potentially from both human-readability and parsing POVs)
with the NOT operator.
How about the contents of an array literal following the initialiser
syntax? Then it would be
int[][]![
[1,2,3,4],
[5,6,7,8],
[9,0,1,2],
[3,4,5,6]
]
Of course, this would be syntactic sugar for the aforementioned
int[][]![
int[]![1,2,3,4],
int[]![5,6,7,8],
int[]![9,0,1,2],
int[]![3,4,5,6]
]
Indeed, ages ago I pointed out that the inability to initialise
non-static arrays seems to be an arbitrary restriction.
http://www.digitalmars.com/d/archives/26695.html
One possible approach to lifting this restrictions is to treat an
initialiser on a non-static array as syntactic sugar for an array literal.
But on the whole, I quite like the int[]! syntax. We could make it work
for associative array literals as well, and at the same time make it
possible to initialise such things.
Stewart.
More information about the Digitalmars-d
mailing list