# Introduction to Expressions

Inaport uses a very powerful expression evaluator and set of functions to allow you to:

- test whether data meets certain conditions
- make changes to the data.

An expression is a sequence of operations on data which produces a result. For example:

2 + 3

is an expression which produces the result '5'. Another expression is:

(2 + 3) * 3

which produces the result '15'.

The expression builder is provided to assist in generating expressions; it provides one click access to all functions, operators, fields in the input data, and many examples of regular expressions, data and number formats. See Using the Expression Builder for more information.

## Operators

The '+' and the '*' in the examples above are called operators. A operator takes one or two operands and does something to them to produce a result. The operator '+' does exactly what you expect - it adds two numbers together and produces another number.

Operators have precedence. Precedence simply means which operator is more powerful than another. For example, compare:

1. (2 + 3) * 3 and

2. 2 + 3 * 3

Naturally , you would expect the first line to produce 15, and the second line to produce 11. The reason for this is that the '*' operator has higher precedence than the '+' operator, which means that it gets evaluated first. Expression 2 is equivalent to (2 + (3 * 3)).

The '+' and '-' operators are also be used in Date Arithmetic. Days can be added to or subtracted from dates to produce a new date. For instance 01/01/00 - 7 = 25/12/99

The operators that are allowed in expressions are shown in the table below, with the order of precedence placed in column one. A precedence of 1 represents the highest precedence.

precedence | Operators | Meaning | Example
1 | ** | Exponentiation | 2**3 = 8
2 | NOT | Logical negation | NOT true = false
2 | .NOT. | Logical negation | exactly the same as NOT Included for those used to dBase functionality
3 | * | Multiply | 2 * 3 = 6
3 | / | divide | 6 / 3 = 2
3 | % | remainder | 7 % 3 = 1
3 | AND | logical AND | true AND false = false
3 | .AND. | logical AND | exactly the same as AND Included for those used to dBase functionality
4 | + | Addition, date arithmetic or string concatenation | 2 + 3 = 5; date() + 5 = current date with 5 days added "aa" + "bb" = "aabb"
4 | - | subtraction, date arithmetic | 5 - 3 = 2 date() - 5 = current date with 5 days removed
4 | & | string concatenation | "aa" & "bb" = "aabb"
4 | OR | logical OR | true OR false = true
4 | .OR. | logical OR | exactly the same as OR Included for those used to dBase functionality
4 | $ | IsIn | "aa" $ "ccaa" = true Returns true or false depending on whether the string on the left of the operator is included in the string on the right.

As shown above, you can use brackets in the expression to change the order of evaluation; expression 1 above uses brackets to force the "2 + 3" to be evaluated before the multiplication.