# User Defined Functions

Chandra Bergmann

User Defined Functions are custom functions made out of and parsable by Airscript. They can be used as part of an application in the same way as out-of-the-box Airscript functions can, including when defining other User Defined Functions.

### The Building Interface for User Defined Functions

User Defined Functions are created in the Connection Builder. Here is what the interface looks like:

New User Defined Functions can be created by clicking the '+' icon next to User Defined Functions in the Tree and selecting User Function Definition from the menu that appears:

For a more detailed dive into how create a new User Defined functions step-by-step, check out Creating a New User Defined Function.

#### Usage

Once a User Defined Function has been created, its Usage – that is, how the function will be called upon within the application – can be edited in the Inspector. User Defined Functions are referenced according to their Namespace and Binding, in the format Namespace#Binding. For instance, the following User Defined Function would be called upon as ABS_CUBED#USER_FUNCTION:

#### Behavior

The Behavior section in the Inspector provides the tools to edit the input and output that the User Defined Function will expect and return:

Airscript functions, User Defined Functions included, only return a single output. You can define the data type of the output by selecting it from the dropdown menu directly underneath Output.

User Defined Functions can accept arbitrarily many inputs; new ones can be added by clicking on the '+' icon at the bottom of the Inputs field. Input defined in this way will be treated as required; the User Defined Function will not run without it. When the function is called upon, input must be given in the order it is listed here. For instance, for some example function EXAMPLE#USER_FUNCTION, which the inputs are listed as follows:

the function must be called upon as:

EXAMPLE#USERFUNCTION(n, test, boolean)

The details of each input can be edited by clicking on them, at which point you'll be allowed to edit the name of the input (via the text field on the right) as well as define the data type (by selecting from a dropdown menu on the left). An input can be deleted by clicking on the '-' icon to its right.

#### Function Body

The Function Body, which dictates the behavior of the User Defined Function in terms of Airscript and the designated input, is defined and edited in the Stage. The Function Body accepts all valid Airscript operators, spanning everything from arithmetic operators to established functions (including other User Defined Functions). For instance, the following code utilizes the Airscript function ABS as well as the multiplication operator in order to return the absolute value of the cube of some input n: