Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents
maxLevel2

Comparison

Several built-in, infix operators allow testing for equality and inequality. For numbers, including <, >, <=, >=, ==, and != are used. For strings, eq, neq, and like are used.

The following are all valid predicate expressions:

Code Block
languagejavascript
themeConfluence
languagejavascript
c >== 5
pageevent:varattr("city") eq!= "Blackfoot"
"Lindon" neq location:city()
weather:curr_temp() < 90
location:city() + ", WA" eq city== app:cities[random:integer(0, app:cities.length()-1)]
time:now() == time:new("2015-08-08")
5 * (weatherrandom:curr_temp(number(32, 212) - 32) / 9 < 0ent:thresholdTemp

As can be seen from the preceding examples, a number of built-in libraries provide predicates that can be used inside predicate expressions. The documentation for those libraries gives details about their operation.

Two special comparison operators are useful with the sort() operator: <=> and cmp. These operators return -1 if the first operand is less than the second, 0, if they're equal, and 1 if the first operand is greater than the second.The  The <=> operator is used with numbers and cmp is used with strings.

Code Block
language
languagejavascript
themeConfluencejavascript
x = 5; 
y = 6;
x <=> y // returns -1
x <=> x // returns 0
y <=> x // returns 1
p = "aab";
q = "abb";
ap cmp bq // returns -1
ap cmp ap // returns 0
bq cmp ap // returns 1

Like

Like takes a regular expression as its second argument and returns true if it matches the string given as its first argument. Arguments to these operators can be any valid expression.

info
Code Block
languagejavascript
themeConfluencelanguagejavascript
spicy = cheese like re/re#(nacho|pepperjack)/#;

Note that when the like operator is used inside a JSONPath expression, the second operand, representing the regular expression, is given as a string. '/(nacho|pepperjack)/'

Membership

There is an infix operator for testing membership, ><. The >< operator tests the number or string in the right operand for membership in the map or array given by the left operand. For maps, membership extends to keys only. 

Code Block
languagejavascript
themeConfluencelanguagejavascript
a = [5, 6, 7];
m = {"a" : 1, "b" : 2};
a >< 6     // returns true
a >< 3     // returns false
m >< "a"   // returns true
m >< "foo" // returns false

...

Compound predicate expressions are created using the operators &&, ||, and not to express conjunction, disjunction, and negation, respectively. Conjunction has precedence over disjunction. Parentheses are used to group expressions for precedence.

Code Block
languagejavascript
themeConfluence
languagejavascript
not a
a && b
a || b
(a || b ) && not c

The operators && and || use short-circuit evaluation semantics

Code Block
val = arg || default

In the example code shown above, the name val is bound to the value of arg provided it is considered to be "true" and otherwise binds it to the value of default. This is similar to, but more general than, the universal operator defaultsTo except that the latter only applies when the value it is operating on is specifically null.