in reply to Determining whether a value is zero.

I don't suppose that you would entertain any argument with your arbitrary definition of what constitutes zero?

Any definition that deems "0" as zero, but "00", "0.0" & "0 " as not, is so arbitrary as to render the challenge pointless.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
  • Comment on Re: Determining whether a value is zero.

Replies are listed 'Best First'.
Re^2: Determining whether a value is zero.
by Corion (Patriarch) on Mar 10, 2011 at 13:31 UTC

    It may be pointless from the sense of practical application. I found it interesting as a way of familiarizing the various representations of zero, and how the various operators treat a scalar (dual-)variable in Perl.

      I'm not adverse to a purely intellectual challenge.

      But the specification of what is and what is not zero doesn't seem to comply with any either real-world or rational definition that I can think of. I cannot think of any existing implementation that would interprete "0" as zero, and not "00" or "0 ". Nor can I see any rational for doing so.

      Without some logic as to why these arbitrary rules have been picked, you might as well do:

      #! perl -slw use strict; use feature qw[ state ]; use Scalar::Util qw[ dualvar ]; my @true = ( 0, "0", 0.0, Scalar::Util::dualvar( 0, 1 ) ); my @false = ( 1, "foo", "00", "0 ", undef, "", Scalar::Util::dualvar( 1, 0 ), "0.0" ); sub isZero { state %isZero; unless( %isZero ) { $isZero{ $_ } = 1 for @true; $isZero{ $_ } = 0 for @false; } return $isZero{ $_ } if exists $isZero{ $_ }; die "Don't know"; } print "$_ : ", isZero( $_ ) for @true; print "$_ : ", isZero( $_ ) for @false;

      As it can be infinitely extended to deal with any set of illogical rules.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        Without some logic as to why these arbitrary rules have been picked,
        Ok, here's the other part of the challenge: what's the logic about what for some people seem to be "arbitrary" or even "illogical"?
Re^2: Determining whether a value is zero.
by Anonymous Monk on Mar 10, 2011 at 13:36 UTC
    There is one point, in "0.0"
Re^2: Determining whether a value is zero.
by JavaFan (Canon) on Mar 10, 2011 at 13:42 UTC
    Any definition that deems "0" as zero, but "00", "0.0" & "0 " as not, is so arbitrary
    Please, take that up with Larry Wall. It isn't my fault that he considered "0" to be false, but "00", "0.0" & "0 " to be true. But then, that guy is well known for his arbitrary decisions which he never entertains any argument with, rendering the entire Perl language pointless.
      he considered "0" to be false,

      That's not quite the same things as considering '00' to be non-zero is it!

      C:\test>perl -e"print '00' == 0" 1

      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        That's not quite the same things as considering '00' to be non-zero is it!
        No, but you were complaining about the arbitraryness. It has the same arbitraryness as for true/false.
        C:\test>perl -e"print '00' == 0" 1
        So what?
        $ perl -E 'say "BrowserUK" == 0' 1 $ perl -E 'say "00" eq 0' $
        Heh, I made the challenge, I make the rules. If you don't like the rules, don't play.
      Certainly is interesting that quoted 00 is true while quoted 0 is false (but it sounds like '0', "0" are special cases).
      perl -E 'say 0 ? q{true} : q{false}' # false perl -E 'say 00 ? q{true} : q{false}' # false perl -E 'say q{0} ? q{true} : q{false}' # false perl -E 'say qq{0} ? q{true} : q{false}' # false perl -E 'say q{00} ? q{true} : q{false}' # true perl -E 'say qq{00} ? q{true} : q{false}' # true
      Perl 5.10.1 on Solaris 10 SPARC.

      Elda Taluta; Sarks Sark; Ark Arks