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.
|