What is the value for D to allow assign bool to char/dchar? For me, it must be an error.
jfondren
julian.fondren at gmail.com
Sat Aug 7 21:57:20 UTC 2021
On Saturday, 7 August 2021 at 21:45:09 UTC, apz28 wrote:
> void main()
> {
> dchar d;
> d = false;
> d = true;
> char c;
> c = false;
> c = true;
> }
true is 1 and false is 0. These are valid char and dchar values.
Some people and languages are on board with this (like APL,
quote: "Ken asked Wolfram why it was that in Mathematica
propositions don’t have values 0 and 1 as in APL instead of True
and False. Wolfram replied that he had no objections, but the
Mathematica implementers were against it."), and some aren't.
```d
assert(2 == true+true);
assert('a' == "ab"[3 > 5]);
assert(2 == iota(5).map!"a>2".sum);
```
More information about the Digitalmars-d-learn
mailing list