'in' syntax for searching arrays

Regan Heath regan at netmail.co.nz
Tue Nov 6 01:34:44 PST 2007


Bruno Medeiros wrote:
> 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)

A map is a piece of paper or book with roads and rivers drawn on it.  <g>

Regan



More information about the Digitalmars-d mailing list