Associative Array Initalizers - Possible Syntax?
Kirk McDonald
kirklin.mcdonald at gmail.com
Mon Feb 12 12:51:23 PST 2007
Xinok wrote:
> 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];
I do not find this a compelling reason to require brackets or
parentheses in all cases. I do like Nicolai's suggestion, though. (It's
very much like Python's syntax, and I believe has been suggested before.)
--
Kirk McDonald
http://kirkmcdonald.blogspot.com
Pyd: Connecting D and Python
http://pyd.dsource.org
More information about the Digitalmars-d
mailing list