Operators

This is Tinderbox Cookbook version 2.0.0, created in conjunction with Tinderbox 5.11.2.

The locale settings used to export this document: en-GB. Most date tests were written/tested on a UK day/month order system and thus tests may fail if exported using different locale settings.

This page explores Tinderbox operators, used in actions, rules, and with the export templates ^action() and ^value().

Deprecation. Some codes are now marked 'deprecated'. This means that while they may still work, such syntax should be avoided. New documents should not use such syntax and existing documents in regular use should be have their code reviewed to avoid retaining deprecated usage.

*

Multiply numbers and repeat strings

description try expect result ok

Multiplying numbers

3*5 15 15 not yet

repeating strings

5*"A" AAAAA AAAAA not yet

/

Divides two numbers

description try expect result ok
6/2 3 3 not yet

division by zero is undefined

5/0 inf not yet
4/-2 -2 -2 not yet

4-2/2 is equivalent to 4-(2/2)

4-2/2 3 3 not yet

+

Add numbers, add items to sets, and concatenate strings.

description try expect result ok

Adding numbers

1+1 2 2 not yet

concatenating strings

"able"+"baker" ablebaker ablebaker not yet

mixing strings and numerals

"able"+27 able27 able27 not yet

Adding a string to a set adds a new element to the set.

$UserSet is "able;baker".

$UserSet+"dog" able;baker;dog able;baker;dog not yet

If you add an element to a set that already contains the element, the set does not change.

$UserSet is "able;baker".

$UserSet+"baker" able;baker able;baker not yet

-

subtract numbers, or remove elements from a set

description try expect result ok

subtracting numbers

5-3 2 2 not yet

Subtracting an element from a set removes that element.

$UserSet is "able;baker".

$UserSet-"baker" able able not yet

Subtracting an element from a set has no effect if the set did not contain the element.

$UserSet is "able;baker".

$UserSet-"dog" able;baker able;baker not yet

String substraction is undefined

"charlie"-"ch" charlie-ch not yet

!

negates a logical value. In Tinderbox, the empty string "", the number 0, and the date never are considered false; all other values are considered true.

description try expect result ok
!(5=2+3) not yet
!(5>1) not yet

$UserFlag is false .

!$UserFlag true true not yet

$UserFlag is true .

!$UserFlag false not yet

Equivalent to ((!0) | 1)

!0 | 1 true true not yet

Equivalent to ((!0) & 1)= 1&1= 1

!0 &1 true true not yet
!(0 | 1) false not yet

>

compares two dates, strings, or numbers

description try expect result ok
5>4 true 1 not yet
5>5 false 0 not yet
5>6 false 0 not yet
50>5 true 1 not yet
dogs>cats true true not yet

strings use lexical comparison

dogs>dog true true not yet

strings use lexical comparison

"50">"5" true true not yet
date(2004,12,1)>date(2001,7,14) true 1 not yet
date(2004,12,1)>date(2007,7,14) false 0 not yet

>=

compares two dates, strings, or numbers

description try expect result ok
5>=4 true 1 not yet
5>=5 true 1 not yet
5>=6 false 0 not yet
50>=5 true 1 not yet
dogs>=cats true true not yet

strings use lexical comparison

dogs>=dog true true not yet

strings use lexical comparison

"50">="5" true true not yet
date(2004,12,1)>=date(2001,7,14) true 1 not yet
date(2004,12,1)>=date(2007,7,14) false 0 not yet
date(2004,12,1)>=date(2004,12,1) true 1 not yet

<

compares two dates, strings, or numbers

description try expect result ok
4<5 true 1 not yet
5<5 false 0 not yet
6<5 false 0 not yet
5<50 true 1 not yet
cats true true not yet

strings use lexical comparison

dog true true not yet

strings use lexical comparison

"5"<"50" true true not yet
date(2001,7,14) true 1 not yet
date(2007,7,14) false 0 not yet

<=

compares two dates, strings, or numbers

description try expect result ok
4<=5 true 1 not yet
5<=5 true 1 not yet
6<=5 false 0 not yet
5<=50 true 1 not yet
cats<=dogs true true not yet

strings use lexical comparison

dog<=dogs true true not yet

strings use lexical comparison

"5"<="50" true true not yet
date(2001,7,14)<=date(2004,12,1) true 1 not yet
date(2007,7,14)<=date(2004,12,1) false 0 not yet
date(2004,12,1)<=date(2004,12,1) true 1 not yet

=

Assign a value to left-side expression.

Use == for comparison of two dates, strings, or numbers

description try expect result ok

Rule: $UserString="Hello"

$UserString Hello Hello not yet

Rule: $UserString=$MyString

$UserString Hello world Hello world not yet

Rule: $UserString= "Hello"; $UserString = $UserString + " " + $MyString

$UserString Hello world Hello world not yet

==

compares two dates, strings, or numbers. While = is sometimes an assignment, == is unambiguously a comparison. Use of = for comparison is now deprecated.

description try expect result ok
5==4 false 0 not yet
5==5 true 1 not yet
1+4==5 true 1 not yet
5==1+4 true 1 not yet

UserString is dogs.

"dogs"==$UserString true true not yet
dogs=="do"+"gs" true true not yet
"do"+"gs"=="dogs" true true not yet
date(2004,12,1)==date("1 Dec 2004") true 1 not yet

!=

The != operator tests inequality

description try expect result ok
5!=4 true 1 not yet
5!=5 false 0 not yet
2+4!=5 true 1 not yet
5!=2+4 true 1 not yet

UserString is dog.

"dogs"!=$UserString true true not yet
dogs!="do"+"g" true true not yet
"do"+"g"!="dogs" true true not yet
date(2004,11,1)!=date("1 Dec 2004") true 1 not yet

comparisons

Examples of comparisons, with special attention to operator precedence

description try expect result ok
(5>3) & (5>2) true 1 not yet
5>3 & 5>2 true 1 not yet
1+2*3 7 7 not yet

$Date is 10/12/2008

$Date>"10/23/2004" true 1 not yet

$Date is 01/01/2000

$Date>"10/23/2004" false 0 not yet