in reply to Re^3: One out of three ain't bad (order)
in thread One out of three ain't bad

True enough. I suppose what's lacking is a commonly-accepted idiom for Boolean conversions. We have 0+ for numeric conversions; so perhaps !! wasn't so bad after all, even though two operations are implied (unless the compiler optimizes them out). 0|| and 1&& would also work.
  • Comment on Re^4: One out of three ain't bad (order)

Replies are listed 'Best First'.
Re^5: One out of three ain't bad (! !!)
by tye (Sage) on Oct 25, 2005 at 03:37 UTC

    No, 0||$x is just $x, not "Booleanized" $x. perl -le"print 0||5" prints 5 not 1 and perl -le"print 1&&@ARGV" x y z prints xyz.

    - tye        

      So, once again in Perl,
      $conjecture->obviously_so == 1 && $conjecture->true == 0
      Thanks, tye, for testing something I should've! (tho' the logic of Boolean diadics not returning Boolean values escapes me...)
        (tho' the logic of Boolean diadics not returning Boolean values escapes me...)

        It allows idioms such as:

        $hostname ||= 'localhost';

        Since that is just short for:

        $hostname= $hostname || 'localhost';

        it'd set $hostname to just 'true' if Boolean operators returned Boolean values. Of course, the above is short-hand for:

        $hostname= 'localhost' if ! $hostname;

        but the first form is the only one that manages to not repeat $hostname, which can be quite an advantage in some cases, or across a bunch of similar cases. And there are other similar idioms that are useful because of this property.

        In any case, it is quite "Perlish".

        - tye