Unofficial wish list status.
Chris Nicholson-Sauls
ibisbasenji at gmail.com
Mon Jan 1 11:02:24 PST 2007
Xinok wrote:
> -- array initialization/literals
> They gave this design for initalizing associative arrays:
> int[char[]] aa = ["one":1, "two":2, "three":3]
>
> This design would be a problem if you used a conditional ? : for the index. My design:
> int[char[]] aa = [["one"] = 1, ["two"] = 2, ["three"] = 3];
> int[][int] aa = [[0] = [15, 30], [1] = [45, 60, 75]];
> int[int][int] aa = [[0][1] = 15, [2][3] = 30]; // This would be nice, though I'm
> not sure if it would work
I believe the choice of the colon for this was based on the syntax for static struct
initializers:
# struct S {
# int i ;
# char[] t ;
# }
#
# static S myS = {i: 42, t: "hello"};
But personally I think something like this would work well for assoc's:
# int[char[]] aa = [
# "one" => 1 ,
# "two" => 2 ,
# "three" => 3
# ]
It makes a new operator, aye, but I don't believe a '=>' is used anywhere else. It also
should not be ambiguous for the compiler, as an array literal's type is taken from the
first element, and this would make the first element a key=>value of type char[]=>int.
-- Chris Nicholson-Sauls
More information about the Digitalmars-d
mailing list