'in' syntax for searching arrays

Daniel Keep daniel.keep.lists at gmail.com
Sun Nov 4 16:48:38 PST 2007



Janice Caron wrote:
> On 11/4/07, Derek Parnell <derek at psych.ward> wrote:
>> If someone says "is 'cat' in that list?" nearly everyone knows exactly what
>> was meant.
> 
> I'd rather have consistency - particularly when it would be so easy to
> add a find() function to do the search-for-a-value thing.

I think his point was that the double meaning for "in" *is* consistent
with how people use the word in every day life.  On the other hand,
there are lots of keywords in D that have completely non-orthogonal
meanings.  The consistency argument is, frankly, a load of codswallow
when you consider that "in" already has *three* unrelated meanings:
"membership test", "precondition" and "pass by value."

And it's not the only keyword like that; static has multiple meanings,
too.  And every other operator in the language can have subtly different
meanings depending on how its been overloaded.  The important thing is
that the operators all do "the right thing" for the given type.

An example: you can't use real[4] + real[4], but you *can* do
vector!(real, 4) + vector!(real, 4).  I mean, they're basically the
exact same thing.  Thus, this is inconsistent, and you shouldn't be
allowed to add vectors.  But that's stupid because adding vectors is
actually *really* useful, and I'm actually quite capable of putting
arrays and vectors into different mental boxes.  Arrays vs. maps is no
different; in that case you're saying that "in" shouldn't be usable on
arrays because it's implemented differently for AAs.

Anyway, you can probably tell which side of the fence I'm sitting on.
Just thought I'd chip in my AU$0.02.

	-- Daniel



More information about the Digitalmars-d mailing list