Project Elvis
Ola Fosheim Grøstad
ola.fosheim.grostad+dlang at gmail.com
Sun Oct 29 20:51:04 UTC 2017
On Sunday, 29 October 2017 at 20:37:21 UTC, bauss wrote:
> But casting to bool is what you use to tell whether something
> is valid or not.
>
> true = valid, false = invalid.
Not really. In mathematics 0 and 1 can be considered as "true"
and "false" for a 2-value calculus, while you might reserve ⊤ and
⊥ for true and false in the logic you use to reason about that
calculus.
Which is why some languages assumes an equality between 0 and
true and 1 and false, but that does not by necessity suggest
valid/invalid.
On the other hand. For things like Unix function call return
values -1 is often used to signify an invalid result, and 0 does
not signify failure.
So if you want strict typing, you have to do something else.
Because C (and thus D) takes the mathematical view on the
relationship between integers and bools and propagate that view
to all other basic types (e.g. floats).
Ola.
More information about the Digitalmars-d
mailing list