www.digitalmars.com         C & C++   DMDScript  

D - const for associative arrays?

reply Steve Adams <adamss ascinet.com> writes:
Is there a way to declare and initialize associative arrays?  Something 
along the lines of:

    const int[char[]] foo =  list of pairs?

Thanks.
Mar 12 2004
next sibling parent reply "Walter" <walter digitalmars.com> writes:
"Steve Adams" <adamss ascinet.com> wrote in message
news:40521D81.4030808 ascinet.com...
 Is there a way to declare and initialize associative arrays?  Something
 along the lines of:

     const int[char[]] foo =  list of pairs?
Currently, there isn't. One way to do it is to use a module constructor to load up the array.
Mar 12 2004
next sibling parent reply "C. Sauls" <ibisbasenji yahoo.com> writes:
When do you think that might become available?  I'm really looking 
forward to it personally, because I have a lot of those module 
constructors doing just that, and it would be nice to get it all in one 
statement.

I'm sure its all been said before, but I'm personally a fan of the : 
syntax...
const int[char[]] FOO = [
     "abc" : 1,
     "def" : 2,
     "ghi" : 3
];

Feels consistant with the struct syntax, and reminds me of Python all at 
once.  :)

-C. Sauls
-Invironz

Walter wrote:
 "Steve Adams" <adamss ascinet.com> wrote in message
 news:40521D81.4030808 ascinet.com...
 
Is there a way to declare and initialize associative arrays?  Something
along the lines of:

    const int[char[]] foo =  list of pairs?
Currently, there isn't. One way to do it is to use a module constructor to load up the array.
Mar 12 2004
parent "Walter" <walter digitalmars.com> writes:
"C. Sauls" <ibisbasenji yahoo.com> wrote in message
news:c2tess$2mki$1 digitaldaemon.com...
 When do you think that might become available?  I'm really looking
 forward to it personally, because I have a lot of those module
 constructors doing just that, and it would be nice to get it all in one
 statement.
Not for 1.0, but better array literals are a good candidate for 2.0.
Mar 12 2004
prev sibling parent Steve Adams <adamss ascinet.com> writes:
Walter wrote:
 "Steve Adams" <adamss ascinet.com> wrote in message
 news:40521D81.4030808 ascinet.com...
 
Is there a way to declare and initialize associative arrays?  Something
along the lines of:

    const int[char[]] foo =  list of pairs?
Currently, there isn't. One way to do it is to use a module constructor to load up the array.
Thanks, I'll use that approach.
Mar 12 2004
prev sibling parent "Phill" <phill pacific.net.au> writes:
I think you will find that info here:

http://www.digitalmars.com/d/arrays.html

Phill.


"Steve Adams" <adamss ascinet.com> wrote in message
news:40521D81.4030808 ascinet.com...
 Is there a way to declare and initialize associative arrays?  Something
 along the lines of:

     const int[char[]] foo =  list of pairs?

 Thanks.
Mar 12 2004