Predefined functions

A predefined function in TL-Script has a specific name that is known globally in all scripts. A predefined function is called directly by its name without first assigning it to a variable. All predefined functions are described in detail here and context help is provided for the function when typing in an editor for TL-Script expressions.

The length of a character string can be determined using the length function, for example (see Length). A number of special rules for predefined functions, when calling

Normal function call

In a normal function call, all parameters are specified in the function brackets. If there are several parameters, the arguments are separated by commas.

length("Hello world!")
subString("Hello world!", 6, 11)

Chained function call

Function calls can be chained without having to nest the calls deep inside each other. The first argument can be placed before the function name. In this notation, a chain of processing steps can be easily constructed in which the result of the last processing step serves as input for the next step.

"Hello world!".substring(6, 11).length()

Especially with long processing chains, it is easy to maintain an overview if each processing step is written in a new line:

"Hello world!"
    .substring(6, 11)
    .length()

Here, "Hello world!" first calculates the characters between the 6. and 11. ("world") and determines the length from this result (5).

Even without forming a chain, the first argument may always precede the function name, e.g. in:

"Hello world!".length()

This notation is equivalent to:

length("Hello world!")

Call with explicit chaining

A chain of function calls as above can only be formed if the last function called returns the appropriate result for the next call. This is not the case for object creation and initialization in particular. For example, the set and add function (see Insert in attribute value) does not return a result. With a normal function call, a temporary variable would have to be inserted in order to create and initialize an object and then add it to a reference:

{
  obj = new(`MyType`);
  $obj.set(`MyType#myProp1`, $myValue1);
  $obj.set(`MyType#myProp2`, $myValue2);

  $otherObj.add(`OtherType#myRef`, $obj);
}

With explicit concatenation, however, object creation and initialization, for example, can also be expressed as one expression without an imperative statement list:

$otherObj.add(`OtherType#myRef`, 
  new(`MyType`)
    ..set(`MyType#myProp1`, $myValue1)
    ..set(`MyType#myProp2`, $myValue2));

The ".." operator ensures that the result of the function call is always the input value (on the left-hand side), regardless of what the function returns. Thus, the result of new(`MyType`)..set(`MyType#myProp1`, $myValue1) is the new object (and not the return value of set). The next initialization can then be carried out on this object and the final result (still the new object) can be inserted into a reference.

Call with named arguments (from 7.6.0)

Some functions with many parameters support the call with named arguments. The problem with normal function calls is that it is no longer easy to see what the individual argument means when it is called. In subString("Hello world!", 6, 11), for example, it is not clear what exactly 6 and 11 mean. Therefore, you can name the arguments passed:

subString("Hello world!", from: 6, to: 11)

With this form of call, you can omit any optional arguments. In a normal function call, you can only omit arguments after the last specified argument.

subString("Hello world!", from: 6)

Only the starting point is specified here, the end is implicitly the end of the string. The result is "world!".

subString("Hello world!", to: 11)

Here, the starting point is omitted, which is implicitly at the beginning of the string. The result is "Hello world".

In contrast, only optional arguments can be omitted at the end of a normal call, as the position of the arguments defines their assignment to the function parameters. In this case, normal function calls can only describe sections from a certain character (substring("Hello world!", 6)) but not up to a certain character.

The call style can be mixed in one call. The first parameters can be specified using positional arguments and all others using named arguments. In the example above, the character string from which the cut is to be made is not named, but only the arguments that define the cut positions. It is important to note that after the first named argument, all further arguments must also be named. For this reason, functions that support any number of arguments (such as Convert to string) cannot be called with named arguments.