> Mailing-List: contact [EMAIL PROTECTED]; run by ezmlm
> Date: 3 Nov 2002 14:58:52 -0000
> From: Smylers <[EMAIL PROTECTED]>
> X-Posted-By: 193.237.84.140
>
> Michael Lazzaro wrote:
>
> > Agreed: the value of comparing a boolean with anything else is not
> > particularly sensible in *any* language.
>
> It isn't particularly unsensible in PHP.
>
> PHP only has one equality operator. If its operands are of different
> types then it casts one operand to match the other, choosing these types
> in order of preference:
>
> bool
> int
> float
> string
>
> That means that comparing a bool with something else first casts the
> something else to a bool, so the comparison works:
>
> $int = 3;
> if ($int == true) { echo 'This gets printed.'; }
Perl has a much finer solution. So, it's possible to express "if
three is equal to two plus one," obviously:
if 3 == 2 + 1 {...}
But few languages can express "if it is true that three is equal to
two plus one" (though the statements are, in fact, equivalent).
However, Perl can:
if (3 == 2 + 1) ~~ true {...}
Even more support for making C<true> a unary function. It's almost
possible to transliterate via markup English logic statements into
Perl:
"if 'two plus two equals three' is not true..."
if (2 + 2 == 3) ~~ {not true} {...}
How's that for self-documentation? :)
(I wrote this to remind people that Perl 6 is still beautiful, in
spite of the line-noise that has been so frequent recently.)
Luke