NOTE: If you are a developer, please use a private wiki based on foswiki/trunk on a daily base ...or use trunk.foswiki.org to view this page for some minimal testing.
Use Item9693 for docu changes for 1.2 and 2.0.

Item2356: QUERY and IF are a little un-intuitive for simple queries

Priority: CurrentState: AppliesTo: Component: WaitingFor:
Normal Closed Engine    
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 smile

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

ItemTemplate edit

Summary QUERY and IF are a little un-intuitive for simple queries
ReportedBy SvenDowideit
Codebase trunk
SVN Range Foswiki-1.0.7, Sun, 20 Sep 2009, build 5061
AppliesTo Engine
Component
Priority Normal
CurrentState Closed
WaitingFor
Checkins Foswikirev:5513 Foswikirev:5521 Foswikirev:5522 Foswikirev:5523 Foswikirev:5533 Foswikirev:5534
TargetRelease minor
ReleasedIn 1.1.0
Topic revision: r14 - 04 Oct 2010, KennethLavrsen
 
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. see CopyrightStatement. Creative Commons LicenseGet Foswiki at sourceforge.net. Fast, secure and Free Open Source software downloads