[Issue 7079] BigInt bool assign
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Dec 9 03:13:13 PST 2011
http://d.puremagic.com/issues/show_bug.cgi?id=7079
--- Comment #4 from bearophile_hugs at eml.cc 2011-12-09 03:13:08 PST ---
(In reply to comment #3)
> > In languages as Java and Pascal boolean values and integer values are two
> > very distinct types. In languages like C/C++/D/Python boolean is a kind of
> > subset of integer type.
> Where did you get the idea that that applies to D?
This program compiles with -w too, a bool is accepted in many situations where
you ask for an integer, like assignments and function arguments:
void foo(int x) {}
void main() {
bool b = true;
int y = b;
foo(b);
}
> > There are many situations where the implicit true -> 1 conversion is handy.
>
> Name one.
Counting true values:
void main() {
auto s1 = "hello";
auto s2 = "hallo";
int hamming_distance = 0;
assert(s1.length == s2.length);
foreach (i, c1; s1)
hamming_distance += c1 != s2[i];
assert(hamming_distance == 1);
}
In a Delphi/Java language you need something like:
if (c1 != s2[i]) hamming_distance++;
> There are many uses for 1 -> true.
Yet in D you need a cast to do it:
void main() {
int x = 1;
bool b = x;
}
test.d(3): Error: cannot implicitly convert expression (x) of type int to bool
> I can't see why:
>
> int a = b > c; should compile.
Because this is how D is designed, coming from C/C++. Languages like
Pascal/Java that keep very apart integer and boolean types are OK, and I accept
their design decisions, but D is not done this way, and I think this will not
change. This is why I think designing BigInt against the way the other parts of
D language are designed is bad.
> >I don't think the implicit true -> 1 conversion will be removed from D2,
>
> This is what I disagree with. It's another evil implicit conversion.
If this implicit conversion will be removed from D, then I agree that it will
be right for BigInt too to forbid it. But the right thing for BigInt is to act
like normal D ints (where possible and meaningful).
This is not a BigInt battle, it's a battle to remove implicit conversions in
normal D ints, and its place is in D newsgroups and another enhancement
request.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list