'in' syntax for searching arrays

Bruno Medeiros brunodomedeiros+spam at com.gmail
Mon Nov 5 14:16:50 PST 2007


Bill Baxter wrote:
> Walter Bright wrote:
>> Denton Cockburn wrote:
>>> I just figure it's done often enough that adding it wouldn't be hard,
>>> especially considering the keyword is already there, and with the same
>>> general meaning.
>>
>> With AAs, the 'in' expression looks for the key, not the value. It 
>> would be inconsistent to overload it to search for values in regular 
>> arrays.
> 
> A foolish consistency.  Arrays and associative arrays are different things.
> 
> --bb

It's inconsistent either way, for that same reason! (that arrays and 
associative arrays are different things). 'in' should not be overloaded 
in any way whatsoever between those two types. Neither to search for 
indexes or values in regular arrays.

Arrays and "associative arrays" are *very* different things. They only 
share the "array" name and the aspect that they are indexable. But their 
semantics are very different. Arrays have a lot more in common with 
lists than "associative arrays". Arrays and lists should have 
appropriately named methods such as 'contains', 'sort', 'slice', etc., 
while "associative arrays" should have other methods such as 
'containsKey', 'containsValue', etc. ('slice' and others don't even make 
sense).

And btw, which languages besides D call associative arrays as 
"associative arrays"? (instead of "maps" or other things more sensible)

-- 
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d mailing list