food for thought - swift 5 released - bottom types, string interpolation, and stuff.
Timon Gehr
timon.gehr at gmx.ch
Sun Apr 14 00:27:18 UTC 2019
On 12.04.19 21:41, Walter Bright wrote:
> On 4/12/2019 6:31 AM, Timon Gehr wrote:
>> "Who's the clown who's put that there? Don't D programmers know about
>> the array index operator?!"
>
> front() is there for arrays as an adapter so one can use range
> operations on it.
My point exactly. x & 1 is not the best implementation of isOdd for all
integer-representing types of x, and you may want to determine if an
integer is odd in generic code. The reason why isOdd is not in Phobos is
that Phobos has poor support for discrete mathematics in general, not
necessarily that isOdd is too easy to implement for built-in integral
types, and I hope my example demonstrates that.
There are of course other reasons why you would want to add functions
with a simple implementations, I already mentioned standardization of
function names, also, e.g. filter!isOdd is both faster to read and
easier to type than filter!(x=>x&1).
Furthermore, it's just not nice when you are solving a problem and
notice that a lot of functions you need to naturally express it are
missing from the standard library and you need to add them to your own
utility library first, presumably being too lazy to add the correct
template constraints.
More information about the Digitalmars-d
mailing list