# Functions

Inaport has a very powerful set of functions that can be used in expressions to perform various operations.

A simple example is the sum() function. It can be used to add together a series of numbers:

sum(2,3,4,5) = 14

Functions can be used anywhere a normal number or string can be used:

sum(1,2,3) + 2 = 8

3 * (sum(4,5) + 3) = 36

Functions have arguments; arguments are the values that appear inside the brackets. In the first example above, the arguments to the sum function where the numbers 2, 3, 4, and 5.

Arguments don't have to be just numbers; they can be fields:

sum(#myField, #field2) - adds together the contents of field 1 and field 2 (see Field Names and IDs for more information)

or they can be other functions:

sum(sum(1,2), sum(3,4)) = 10

Inaport allows you to have as many brackets and functions inside functions as you need:

sum(sum(sum(sum(1,2), 3), 4), 5) = 15

(although it does get rather hard to read if you nest them too deep).

Many of the functions use Regular Expressions, which are very powerful ways of describing patterns in text. For example, the contains() function accepts a source and a regular expression. It tests to see if the source has a sub string which matches the regular expression, and returns true or false:

contains("aa Bccn", "B.*n") = true

In this example, the regular expression is "B.*n" which matches all strings which start with 'B' and end with 'n'. It therefore matches "Ban", "Baan", "Brown" and many other strings.