Item2356: QUERY and IF are a little un-intuitive for simple queries
Priority: Normal
Current State: Closed
Released In: 1.1.0
Target Release: minor
Applies To: Engine
Component:
Branches:
I was thinking about optimising parsed queries (basically for true&false to be nop's) and thought I'd examine what the code thinks is truthieness..
I'm not sure its 'right' in the head
sub test_true {
my $this = shift;
#nope, parse failure (empty Expression) :/
#$this->simpleTest( test => "0", then => 1, else => 0 );#A
$this->simpleTest( test => "1", then => 1, else => 0 );#B
$this->simpleTest( test => "9", then => 1, else => 0 );#C
#surprisingly..
$this->simpleTest( test => "-1", then => 1, else => 0 );#D
$this->simpleTest( test => "-0", then => 1, else => 0 );#E
$this->simpleTest( test => "0.0", then => 1, else => 0 );#F
##and again as strings..
$this->simpleTest( test => "'1'", then => 1, else => 0 );#G
$this->simpleTest( test => "'9'", then => 1, else => 0 );#H
#surprisingly..
$this->simpleTest( test => "'-1'", then => 1, else => 0 );#I
$this->simpleTest( test => "'-0'", then => 1, else => 0 );#J
$this->simpleTest( test => "'0.0'", then => 1, else => 0 );#K
}
sub test_false {
my $this = shift;
$this->simpleTest( test => "not 1", then => 0, else => 1 );#L
$this->simpleTest( test => "1 = 2", then => 0, else => 1 );#M
##and again as strings..
$this->simpleTest( test => "'0'", then => 0, else => 1 );#N
}
commited to trunk's Fn_IF.pm
it also worries me a little that the number zero is internally the representation for
false
, but that when parsing user input, the number zero is considered undefined.
--
SvenDowideit - 14 Nov 2009
You don't say what result you expect in each case. However the new tests show up a couple of parser problems, that I've fixed. Better?
--
CrawfordCurrie - 15 Nov 2009
some notes:
The number 0, the strings ’0’ and ’’, the empty list "()", and "undef" are all false in a boolean context. All other values are true. Negation of a true value by "!" or "not" returns a special false value. When evaluated as a string it is treated as ’’, but as a number, it is treated as 0.
=man perlsyn=
True or False? A Quick Reference Guide including lots of truth tables and other handy charts
use
0 but true
when useful (which means exactly what it says)
--
WillNorris - 16 Nov 2009
lets call it much better
--
SvenDowideit - 02 Jul 2010