User-Defined Functions

Custom “User-Defined Functions” can be created for a project and will be available for workflows and jobs within that project.

The user-defined function dialog can be opened from the toolbar button in Atrium or Workbench.

Atrium

../_images/udf1.png

User-Defined Function Dialog:

../_images/atriumUDF.png

User-defined functions can be edited directly in Atrium. The code editor supports syntax highlighting to aid composition.

Syntax validation occurs on save and will prompt you if errors are encountered. Note that function names must begin with “A-Z”, “a-z”, or “_”.

Workbench

../_images/toolbar_functions.png

User-Defined Function Dialog:

../_images/udf_dialog.png

Creating and Editing User-Defined Functions

User-defined functions can be edited visually in the Expression Builder or as text in the Code Editor.

Creating a new User-Defined Function

To demonstrate creating a user-defined function we’ll create a simple function that returns the cube of a number.

Within the User-Defined Function dialog, click the ‘+’ button button in the lower left corner and fill in the “Function Name” field of the dialog with our function name, “cubed”. Click “Create” to enter the expression builder.

../_images/udf_create.png

Adding arguments to User-Defined Functions

Our function takes one argument, which we’ll call “x”, so click the “+” button on the “args” tab. Enter “x” in the “Argument Name” field and click “Add” to add it to our function.

../_images/udf_create_arg.png

Editing the body of User-Defined Functions

Editing the body of a user-defined expression is the same as editing any other expression using the Expression Builder. Drag and drop arguments, built in functions, user-defined functions, and constants from the picker to build your expression.

In our example we drag over our newly-created “x” argument three times and change the operators between them to multiply “*”.

../_images/udf_create_cubed.png

Click “Save” at this point to add it to the list of functions in the user-defined function dialog.

At this point the function is created but not saved to the project. You may edit other user-defined functions or click “Save” on the user-defined function dialog to save your changes to the project.

Deleting a User-Defined Function

To delete an existing user-defined function, open the user-defined function dialog, and click once on the function you’d like to delete, then click “Delete” or press the “Backspace” key. To finalize this process, click “Save”. If you do not wish to save your changes, click “Cancel”.

Warning

Editing the argument list or deleting a user-defined function will break existing jobs and workflows if they depend on that function.

User-Defined Functions in Expressions

User-Defined Functions can be selected for use in any expression from the “udf(x)” tab in the Expression Builder. They can be used anywhere in your expression just like Clario’s built-in functions.

User-Defined Functions in Template Strings

User-Defined Functions that take no arguments can be thought of as constants and can be used on Clario Nodes (such as Read File, and Write File) that allow Template Strings.

Examples could be:

:FUNCTION asOfDate() = '2015-10-31'
:FUNCTION asOfStartOfMonth() = date(yearOfDate(asOfDate()), monthOfYear(asOfDate()), 1)

Within a Template String these no-argument user-defined functions can referenced by name between braces. For example to create a filename like “myFile_2015-10-31.csv” one could use the a template string using the above user-defined function “asOfDate” like:

myFile_{asOfDate}.csv

See ClarioScript Guide for more information on Template Strings.