Proposal: struct and array literal syntax
Jarrett Billingsley
kb3ctd2 at yahoo.com
Tue Jun 20 08:21:59 PDT 2006
"Chris Miller" <chris at dprogramming.com> wrote in message
news:op.tbft9dffpo9bzi at moe...
> This is an old idea I had, and also applies to struct initializers which
> now has ambiguity with literal delegates.
>
> Given the following struct:
> struct MyStruct { int foo; int bar; }
> can be created with the following proposed syntax:
> MyStruct!{3, 4}
> which can be used in initializers and anywhere else MyStruct is expected.
>
> For array initializers, see the following proposed syntax:
> int[]![6, 7, 8, 9]
> which creates a dynamic array of 4 int elements.
> This as well can be used in initializers and anywhere else such an array
> is expected.
I like it, and it doesn't seem to introduce any ambiguity in the grammar,
since if you're instantiating a templated struct, the ! will be immediately
followed by a left paren, and not a left brace. And of course you never use
! with arrays. It also solves the problem of parsing the array literal,
since
int[][6]
Would be parsed as a type, while
int[]![6]
Would be parsed as an array literal.
More information about the Digitalmars-d
mailing list