Appendix 2: AMDL Operators
This section details the full list of operators within AMDL and their usage.
Operator Precedence
In the table below, all AMDL operators are listed in precedence order from highest to lowest. Operators in the same row of the table have the same precedence. Each operator is left, right, or non-associative as follows:
-
Left-associative operators of the same precedence bind to the left:
e1 op e2 op e3
becomes(e1 op e2) op e3
. -
Right-associative operators of the same precedence bind to the right:
e1 op e2 op e3
becomese1 op (e2 op e3)
. -
Non-associative operators do not appear in contexts where their binding is ambiguous.
Operator |
Associativity |
---|---|
. ( ) |
left |
[ ] |
none |
! ~ |
right |
* / |
left |
+ - . . ~: |
left |
> > = < < = |
left |
== != |
left |
Collection operators |
right |
&& |
left |
|| |
left |
~? |
right |
?? |
right |
? : |
right |
The following sections on operators describe what the above operators mean.
Mathematical Operators
Operators: + - *
/
As well as
operating
on
numbers, +
and -
can
also
operate on
times and
durations. You can
add or
subtract
durations,
and add or
subtract a
duration to
a time.
Example |
Effect |
---|---|
|
Basic addition. This evaluates to 3. |
|
Returns the value of the amount field in the event minus 50. |
|
Returns the |
|
Returns a count divided by a number. |
String Concatenation Operator
Operator: ..
This operator concatenates any two strings, numbers, durations, or times as strings. For non-strings this is done in such a format that they can be coerced back to their original types.
Example |
Effect |
---|---|
|
Evaluates to "Hello World". |
|
Produces a full name from component parts. |
Comparison and Equality Operators
These return a boolean value indicating the result of the comparison. Note that the first two operators can be applied to strings as well as numbers, durations, and times. However, the latter four cannot be used for strings.
Operator |
Description |
Example |
Effect |
---|---|---|---|
== |
equals |
|
This is always true. You can also check for equality amongst strings. The above is always false. |
!= |
does not equal |
|
Checking an event field is not equal to "999". |
< |
less than |
|
Checking an event field is more than a parameter value. |
<= |
or equal |
|
Checking an event field does not exceed a parameter value. |
> |
greater than |
|
Checking an event field is less than a parameter value. |
>= |
greater than or equal |
|
Checking an event field is equal to or less than a parameter value. |
Event fields can appear either side of the comparison operator.
Boolean Operators
These operators are used upon Boolean values.
Operator |
Description |
Example |
Effect |
---|---|---|---|
&& |
AND |
|
This is only true if both fields are true. |
|| |
OR |
|
This is only false if both variables are false. |
! |
NOT |
|
This is always false. |
Collection Membership Operators
These operators are used to test membership of a collection, and return a Boolean value. In usage, the left-hand operand must always be some form of collection, and the right-hand operand the element of the collection whose membership is being tested.
Operator |
Description |
Example |
Effect |
---|---|---|---|
~# |
contains |
|
Checking that a list in the event contains the value 20.00. Checking whether a string in the event is contained within a pre-defined collection of values. |
!# |
does not contain |
|
Checking that the country field in the event is not one of "GB", "US" or "IS". |
Collection Comparison Operators
These operators perform comparison operations upon all elements of a collection and return the Boolean combination of the results. The left operand must always be a collection and the right operand that which is to be compared.
Operator |
Description |
Example |
Effect |
---|---|---|---|
==# |
All equal to value |
|
All elements of the ordered collection are equal to 1, so this is true. |
!=# |
None equal to value |
|
None of the elements in the collection are equal to "strawberry", so this is true. |
<# |
All less than value |
|
Check that all values are less than to some pre-defined threshold. |
<=# |
All less than or equal to value |
|
Check that all values are less than or equal to some pre-defined threshold. |
># |
All greater than value |
|
Check that all values are greater than to some pre-defined datetime. |
>=# |
All greater than or equal to value |
|
Check that all values are greater than or equal to some pre-defined threshold. |
Ternary Operator
This operator allows one of two operations to be evaluated based upon a boolean condition. The operator is a useful control flow tool to use if, for instance, there are special cases that need treatment.
Operator |
Description |
Example |
Effect |
---|---|---|---|
? : |
Evaluate value x if boolean is true, else evaluate value y |
Copy
|
If the event type is "registration",
this evaluates to the value of
|
? |
|
Copy
|
The 'else' part of the ternary operation is optional. If the Boolean condition evaluates to false, expression evaluation stops. |
Switch Case Operator
This operator allows one of many operations to be evaluated based upon a switch expression. This is useful if you have several special cases for the same variable, each of which needs different treatment.
Operator |
Description |
Example |
Effect |
---|---|---|---|
~? |
Evaluate multiple operations |
Copy
|
Check the event amount against a different
threshold based on the |
|
|
Copy
|
The 'default' case is optional. In this case, if the expression does not evaluate to one of the case labels, the expression evaluation stops. |
Case labels must be a fixed value or a 'default'. Currently, switching based upon variable expressions is not supported. Also note that every switch case must be terminated by a semicolon.
'Default Value' Operator
In AMDL,
expression
evaluation
stops if a
referenced variable
does not
exist. The
??
operator
allows a
default
value to
be
specified if
an
expression
cannot be
evaluated.
Operator |
Description |
Example |
Effect |
---|---|---|---|
?? |
This operator is used if the field does not exist (because data has not been populated). The operator is also used if the field contains null values. |
Copy
|
If the event does not contain a field called
You can default to the value of another field or a state or other variable as well as a fixed value. |
?? |
This operator is used if the field does not exist (because data has not been populated). The operator is also used if the field contains null values. |
Copy
|
You can default to the value of another field or a state or other variable as well as a fixed value. |
'Exists' Operator
This operator checks whether evaluation of a reference returns a non-null value.
Operator |
Description |
Example |
Effect |
---|---|---|---|
~ |
Field Exists |
Copy
|
Evaluates to true if
the |
|
|
Copy
|
Evaluates to true if
the |
Regular Expression Matches Operator
This operator checks whether the left string operand matches the regular expression contained in the right operand.
This operator can only be applied to strings. For more information on regular expressions, see Outputting Values.
Operator |
Description |
Example |
Effect |
---|---|---|---|
~= |
Field matches regular expression |
Copy
|
Checks whether the postcode starts with "CB". |
Regular Expression Substitution Operator
This operator performs a substitution specified in the right operand on the left string operand.
This operator can only be applied to strings. For more information on regular expressions, see Outputting Values.
Operator |
Description |
Example |
Effect |
---|---|---|---|
~: |
Substitute values in operand |
Copy
|
Substitutes dots with dashes, resulting in "1970-01-01". Regexes can be quoted or unquoted. |