Associative Array Initalizers - Possible Syntax?

renoX renosky at free.fr
Tue Feb 13 14:13:11 PST 2007


cracki a écrit :
> Kirk McDonald Wrote:
>> 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.)
> 
> 
> I agree. Requiring brackets makes not much sense. This is not lisp.
> We have operator precedence and we can make use of it. And if that
> fails, use parens. No big deal.
> 
> I also prefer the "[...]" style to the python/ruby/JSON "{...}"
> style. It's consistent with nromal array literals and spares the
> curlies from getting overloaded yet another time.

Agreed, if ':' conflicts too much with '? :' (and I don't think it does, 
parenthesis are here to avoid the problem) then let's use '->' or ':>' 
instead of ':', not a big deal.

Otherwise don't use any special syntax, after all, an associative array 
is a just list of key,value pair so

int tab[char[]] = [["key", 10], ["key2", 11]];

But I really dislike the idea of separating keys and values, sure 
sometimes this is terser but it's also much more likely to induce hard 
to find errors.

renoX



More information about the Digitalmars-d mailing list