Short Boolean form

Tinderbox Icon

It is possible to cite attribute tests in both a long form:

if($MyBoolean == true) 

if($MyBoolean != true) 

or a simple short form:

if($MyBoolean) 

if(!$MyBoolean) 

Note in the negative version the '!' moves in front of the attribute name (and the $-prefix). Thus !$MyString means $MyString has no value set whilst !$Name(Test) causes a reverse pattern query where all note's whose title does not include the string "Test" are matched.

Prior to v5.0.0 the short form failed in certain contexts and it was advisable to use the 'full' syntax; this requirement should not fall away allowing shorter code. Prior to v5.5.4, the negative form was misinterpreted if not the first argument in the expression.

Though the short form is primarily for Boolean attributes, where another data type can be coerced to a true/false equivalent the short form may be tried. the coercion being tested depends on the attribute type's default value. Any value other than the default, results in a coercion of true. $ChildCount is a number type attribute so the default is zero. Both the code examples below equate to the same test but the latter is shorter - useful in longer, more complex expressions.

if($ChildCount > 0) {... if($ChildCount) {...

The converse would be:

if($ChildCount < 1) {... if(!$ChildCount) {...

Note that the short Boolean form, whilst coercing non-Boolean type values to a true/false occurs it is not testing whether the default value is inherited or was explicitly set; qv use of the |= operator.


Possible relevant notes (via "Similar Notes" feature):

Up: Actions & Rules
Previous: Setting an attribute to (no value)  Next: Setting an attribute to re-enable inheritance 

A Tinderbox Reference File : Actions & Rules : Short Boolean form

Quicklinks: Attributes | Action Codes | Export Codes | Designators | Date Formats | aTbRef Site Map

[Last updated: 16 May 2012, using v5.11.1]


Search:

Google search aTbRef for:  


Creative Commons Licence

aTbRef by Mark Anderson is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.

[See aTbRef CC licence Attribution & Waiver info]

Made with Tinderbox