Comparison operators can be used to compare two values.
cmp
Evaluates to:
<0 if expr1 < expr2
0 if expr1 = expr2
>0 if expr1 > expr2
Only comparable value types may be compared. All numeric types are comparable to one another. All other types are only comparable to themselves. Lists are compared item-by-item (akin to alphabetizing words). Strings are compared case-sensitively. The null value is comparable to any value; it is equal to itself, and less than all other values.
Used in the following format, where expr
can be any expression, expr1
must be of comparable type to expr2
and expr2
must be of comparable type to expr1
:
cmp(expr1, expr2)
The return value type is an integer.
Examples
cmp(3, 3.00) # value: 0
cmp(1, 2) # value: <0
cmp(list(1,"a"), list(1.0,"a")) # value: 0
cmp(list(1,2,3), list(1,2)) # value: >0
cmp("abc", "ABC") # value: <0
cmp("abc", 123) # ERROR
cmp(null, "") # value: <0
cmpl
Evaluates to:
<0 if str1 < str2 (case-insensitively)
0 if str1 = str2 (case-insensitively)
>0 if str1 > str2 (case-insensitively)
If both parameters are null, evaluates to 0. If only one parameter is null, it is less than the other. Used in the following format, where str1
must be of type string and str2
must be of type string:
cmpI(str1,str2)
The return value type is integer.
Examples
cmpI("abc", "ABC") # value: 0
cmpI("abc", "bcd") # value: -1
cmpI("abc", null) # value: 1
cmpI(null, null) # value: 0
equals
Evaluates whether all the parameters are equal. Numeric values (double, integer, long integer) are equal if their values are equal, regardless of type. Other values, however, are equal only if their types are equal (and their values are equivalent). Lists are equal if and only if all of their elements are equal. Strings are compared case-sensitively. The null value is equal only to the null value.
Used in the following format where expr
, expr1
and expr2
may be any expression:
equals(expr1, expr2, {expr}*)
expr1.equals(expr2, {expr}*)
The return value type is a Boolean.
Examples
equals(3, long(3), 3.00) # value: true 3.equals(long(3), 3.00) # value: true
equals(list(1, "a"), list(1.0, "a")) # value: true list(1, "a").equals(list(1.0, "a")) # value: true
equals("abc", "ABC") # value: false
"abc".equals("ABC") # value: false
equals("abc", 123) # value: false
"abc".equals(123) # value: false
equals(null, string(null)) # value: true
null.equals(string(null)) # value: true
equals(null, "") # value: false
null.equals("") # value: false
equals(null, list()) # value: false
null.equals(list()) # value: false
equalsI
Evaluates whether all the string parameters are equal, case-insensitively.
If all of the parameters are null, evaluates to true. If some but not all of the parameters are null, evaluates to false.
Used in the following format, where str
, str1
and str2
must be strings:
equalsI(str1, str2, {str}*)
str1.equalsI(str2, {str}*)
The return value type is a Boolean.
Examples
equalsI(1, 1) # ERROR
1.equalsI(1) # ERROR
equalsI("abc", "ABC") # value: true
"abc".equalsI("ABC") # value: true
max
Evaluates to the maximum value among the parameters. If multiple parameters are equivalent to the maximum value, evaluates to the first among them.
Uses exactly the same ordering criteria as cmp. Used in the following format, where expr
must be any expressions, of comparable type to the other parameters:
max({expr}+)
The return value type varies.
Examples
max(3.3, long(5), 2, 5) # value: 5 (long)
max("apple", "cat", "dog") # value: "dog"
max("1", 2) # ERROR
min
Evaluates to the minimum value among the parameters. If multiple parameters are equivalent to the minimum value, evaluates to the first among them.
Uses exactly the same ordering criteria as cmp. Used in the following format, where expr
must be any expressions, of comparable type to the other parameters:
min({expr}+)
The return value type varies.
Examples
min(3.3, long(2), 2, 5) # value: 2 (long)
min("apple", "cat", "dog") # value: "apple"
min("1", 2) # ERROR
notEquals
Evaluates to false if and only if all the parameters are equal.
See the equals operator for details. Used in the following format where expr1
and expr2
may be any expression:
expr1 != expr2
expr1.notEquals(expr2)
notEquals(expr1, expr2)
The return value type is a Boolean.
Examples
# by definition:
($foo != $bar) = (not ($foo = $bar)) # true
1 != 2 #true
notEquals(1,2) #true