Associative Array Initalizers - Possible Syntax?
Xinok
xnknet at gmail.com
Mon Feb 12 12:42:18 PST 2007
Nicolai Waniek Wrote:
> I don't like each version you provided. The most readable and D-ish (in
> comparison to static initialization) would be something like this example:
>
> char[][][char[]] languageTokens =
> [
> "comments" : ["\\*", "*\\", "//", "\\+", "+\\],
> "type" : ["bool", "int", "double", "float"]
> ];
>
> and so on.
The one problem with that example is expressions which would make use of conditionals. Technically, it could work because conditionals have a fixed number of arguments, but it would be hard to read if both sides used conditionals.
int[int] arr = [a > b ? a : b : c > d ? c : d];
You could argue that you could use parenthesis. Well, then it just essentially becomes my syntax, except using parenthesis instead of square brackets [].
int[int] arr = [(a > b ? a : b) : c > d ? c : d];
Compare against:
int[int] arr = [[a > b ? a : b] = c > d ? c : d];
More information about the Digitalmars-d
mailing list