On Sunday, 28 April 2013 at 23:37:23 UTC, Andrei Alexandrescu
wrote:
On 4/28/13 7:19 PM, Mehrdad wrote:
Integer logic: 1 + 1 = 2 = 0 (mod 2)
Boolean logic: 1 + 1 = 1 = 1
Well D doesn't implement Boolean operators for + and *.
Instead, one would need to use | and & respectively.When + and
* are used with bool, promotion to int happens.
I think it's safe to assume D will never implement the Boolean
meaning of + and *.
Sure. But when bool behaves only halfway like an integer (why
doesn't it truncate when casting?) and it _also_ will never
implement Boolean algebra with + and * (which is fine by me, I
never requested that it does) then it should fix _one_ of those
two aspects of itself in order to be self-consistent.
We threw out the Boolean algebra fix, so the only choice is to
either make it behave entirely like an integer, or to make it be
a completely different type.
In other words, we need to either:
1. Make int->bool truncate, or
2. Stop allowing implicit bool->int conversions (explicit
conversions like in if/while/etc. are of course not included here)