User-defined functions

In addition to built-in functions, you can declare your own.

User-defined functions are declared in the functions block. You cannot use variables in them: you can only pass their values as function arguments. If your function name matches the name of a built-in function, your function will take priority.

Functions can be declared in nested elements. If the name and arguments of several user-defined functions match, the function closest to the call point will take priority.

Field values

Example of function declaration
"functions": [
  {
    "name": "increment",
    "body": "@{value + 1}",
    "return_type": "integer",
    "arguments": [
      {
        "name": "value",
        "type": "integer"
      }
    ]
  }
]

The declared function returns the passed argument "value" increased by 1.

When declaring a function, you need to fill in the following fields:

  • "name" — name;

  • "body" — function body;

  • "return_type" — type of returned data;

  • "arguments" — list of function arguments. Each argument corresponds to a pair of "name" (name) and "type" (type).

View an interactive example