== (equality)

Tinderbox Icon


Operator Type:   Operator
Operator Scope of Action:   Query
Operator Purpose:   Boolean (query)

The operator to test equality (i.e. 'is the same as') is '==', two equals signs. Note that this replaces older syntax where a single equals sign was used contextually for both assignment and equality tests.

This operator is used either in agent queries or in the conditional part of an if(condition){action} code. It is the functional opposite of the '!=' inequality test.

This test cannot be meaningfully applied to Set or List type attribute data, as the entire attribute value is matched, rather than individual values as might otherwise be assumed. For these data types use the .contains() or .icontains() operators instead, noting the scope for ambiguous matching due to stemming of words ("car" with match "car", "cars" and "carrot").

Equality testing can be negated, i.e. tested for a non-match, or combined with greater/less than for a range of tests as further explored in Basic Comparison Codes.

For a case-insensitive lexical equality test, use a lowercase on-the-fly transform:

"Absquatulate".lowercase == "absquatulate" 

If we set $MyString to "Absquatulate", then:

$MyString.lowercase == "absquatulate" 

$MyString.lowercase == "$MyOtherString(Agent) 

Note the stored left-side value isn't altered, but its transformed version is used in the test giving a case-insensitive comparison. This method only works for upper/lower case comparisons; accented characters are lexically different characters regardless of case.

Equality and List/Sets

Using == (and !+) with Lists & Sets means you're checking the entire literal contents, i.e. a string like "ant;bee;cow" rather than by individual sub-value: "ant" and "bee" and "cow". Thus the equality test can't be used to check if the attribute contains a discrete value - use .contains() instead. This shows up a difference between lists and sets. Although the literal value of a set may hold values in any order, when tested in code, they are being tested after sorting into (some**) order. Incidentally, this is why you can't set a sort order as you can with a list as internally your given sort order is ignored. Consider $MySetA and $MyListA both with the values "ant;bee;cow". $MySetB and $MyListB both have the value "bee;ant". Now:

$MySetA == $MySetB gives FALSE

$MyListA == $MyListB gives FALSE

both are expected. Now make both the B attributes value "bee;ant;cow"

$MySetA == $MySetB gives TRUE

$MyListA == $MyListB gives FALSE

This is because the Set compares the literal result of sorted values, whereas the list

doesn't. But

$MyListA == $MyListB.sort gives TRUE

This is in effect what's happening with the sets, as in:

$MyListA.sort == $MyListB.sort 

whereas in our last example above, $MyListA was already in default sort order so no applied sort was required.


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

Up: Query Boolean operators

A Tinderbox Reference File : Actions & Rules : Operators : Action Operator Types : Query Boolean operators : == (equality)

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