BlazingWhitester:
> If 'in' operator was overladable, users would expect it to have some
> known complexity.
Like O(n) for a linear search in an array.
> Having sintactic sugar for some operation means that it is supposed to
> be used widely, and using O(n) operations all over the place is not a
> good idea.
I have to search chars in strings, substrings in strings and items in arrays
about equally often if the syntax is built-in or it comes from one or more
library functions.
Well, not having a built-in array search, in D code I sometimes replace:
x in [1, 5, 7]
with
(x == 1 || x == 5 || x == 7)
that's just worse, longer, more bug-prone, less easy to read, and even a *dumb*
compiler as Shedskin is able to turn the first into the second when the array
is short.
> Also, IMO, it has no real advantage, why not use std.algorithm.find instead ?
The syntax is worse, I don't like to call a function for something so common
and basic. It's like calling a library function to join two strings (and
find("hello", "llox") doesn't return a boolean).
Bye,
bearophile