The type [((Int): Int); 2] specifies an array type of two functions that accept an integer and return an integer. An additional argument label can be provided so that function calls use the label to provide an argument value for the parameter. Argument labels must be named in such a way that they make sense from the point of view of the function call. When a function m:f/N is called, the code of the function is found first. If the function cannot be found, an undef run-time error occurs. Note that the function must be exported to be visible outside the module in which it is defined. Prerequisites must be true shortly before the function is executed. Prerequisites are part of the function and are introduced by the pre keyword followed by the condition block. In postconditions, the special constant result refers to the result of the function.
A function clause consists of a clause header and a clause body separated by ->. Functions can be nested, that is, the code of one function can declare other functions. Functions can also be used as expressions. The syntax is the same as for function declarations, except that function expressions have no name, that is, they are anonymous. Argument labels precede the parameter name. The special argument label _ indicates that a function call can omit the argument label. If no argument label is declared in the function declaration, the parameter name is the argument label of the function declaration, and function calls must use the parameter name as the argument label. A function called f in the module m and with aryanity N is often called m:f/N. A condition block consists of one or more conditions. Conditions are expressions valued at a Boolean value.
They should not call any function, that is, they can have no side effects and must be pure expressions. Additionally, conditions may not contain function expressions. A clause header consists of the function name, a list of arguments, and an optional Guard sequence that begins with the when: keyword in parentheses and also controls the priority. For example, a function type ((Int): ((): Int)) is the type of a function that accepts an Int argument and returns another function that does not accept arguments and returns an Int. A function can refer to variables and constants in its outer regions in which it is defined. It is called a closure because it closes on these variables and constants. A conclusion can read from variables and constants and assign them to the variables it references. Each parameter must have a name, that is, the name under which the value of the argument is available in the function. The most commonly used BIFs belonging to erlang(3) are automatically imported. They do not need to be preceded by the name of the module. Automatically imported FDIs are specified in the ERTS erlang(3) module. For example, standard conversion FSAs such as atom_to_list and FBI authorized in Guards can be called without specifying the module name.
Functions are values, that is, they can be assigned to constants and variables and passed as arguments to other functions. This behavior is often referred to as «top-notch features.» There is no support for optional parameters, that is, default values for parameters, and variadic functions, that is, functions that take any number of arguments. Now fact(0) is called and the function clauses are analyzed sequentially again. First, model N is compared to 0. The match is successful, but the goalkeeper (N>0) is wrong. Second, model 0 is associated with 0. Pairing succeeds and the body is evaluated: Functions can be called (called). Function calls must provide as many argument values as the function has parameters. The name of the function is an atom. Each argument is a model.
Conditions can be written on separate lines, or multiple conditions can be written on the same line, separated by a semicolon. This syntax follows that of statements. If the function does not have a return type, it implicitly has a null return type. Parameter types should be enclosed in parentheses, followed by a colon (:) and end with the type of return. The entire function type must be enclosed in parentheses. . . .