'in' syntax for searching arrays

Derek Parnell derek at psych.ward
Sun Nov 4 14:17:10 PST 2007


On Sun, 04 Nov 2007 12:13:35 -0800, 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.

No it wouldn't.

If someone says "is 'cat' in that list?" nearly everyone knows exactly what
was meant. If the list is 'ordered' (i.e. an AA) the person was looking for
an index of 'cat', and if the list was not 'ordered' (a regular array) the
person was looking for content of 'cat'.

For example, I have a dictionary and wonder if 'cat' is in it. I look up
the word "cat" instead of scanning every page for the first mention of a
cat. I have a newspaper article about dog training and wonder if 'cat' is
in it, so I scan for the first mention of a cat.

It is not an inconsistant overload. For such an example of inconsistant
overloads see "static", or "in" when used with DbC.

-- 
Derek Parnell
Melbourne, Australia
skype: derek.j.parnell



More information about the Digitalmars-d mailing list