'in' syntax for searching arrays
Ary Borenszweig
ary at esperanto.org.ar
Mon Nov 5 17:25:16 PST 2007
Bruno Medeiros escribió:
> 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)
>
PHP: http://ar.php.net/array
More information about the Digitalmars-d
mailing list