Static associative arrays?

Derek Parnell derek at psych.ward
Fri Feb 16 06:15:43 PST 2007


On Thu, 15 Feb 2007 23:07:54 -0800, Gregor Richards wrote:

> It would be nice to have a static associative array syntax analogous to 
> the static array syntax. Something like this perhaps:
> 
> char[][char[]] a = [ "a" : "Apple", "b" : "Banana", "c" : "Cantelope", 
> ... ];
> 
> This syntax is unambiguous (though admittedly complex) even for 
> arbitrarily complex AAs:
> 
> char[int][char[][char[]]] a = [ [ "a" : "b", "c" : "d" ] : [ 0 : 'e', 1 
>: 'f' ] ];
> 
> It also has the added advantage of being similar to the static struct 
> syntax.
> 
> 
> To be honest, I don't need static associative arrays desperately, but I 
> also don't think I need to explain why it would be useful.

I still prefer then syntax ...


 char[][char[]] a = [ "a" = "Apple", "b" = "Banana", "c" = "Cantelope", 
 ... ];
 
 
 char[int][char[][char[]]] a = [ [ "a" = "b", "c" = "d" ] = [ 0 = 'e', 1 
= 'f' ] ];

because the '=' makes it more obvious what data is being assigned to which
key.


-- 
Derek Parnell
Melbourne, Australia
"Justice for David Hicks!"
skype: derek.j.parnell



More information about the Digitalmars-d mailing list