Associative Array Initalizers - Possible Syntax?

Bill Baxter dnewsgroup at billbaxter.com
Tue Feb 13 16:22:41 PST 2007


renoX wrote:
> 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]];

Except ["key",10] is currently invalid since it's two different types in 
a list.  You could make it work with Tuples though.  But a syntax nicer 
than Tuple!("key", 10) would be cool.

--bb



More information about the Digitalmars-d mailing list