Functions in Erlang
Functions are central in Erlang. We’ll learn about functions with a few different examples.
To run this Erlang program:
In Erlang, functions are defined within modules. We define the module name at the top of the file and export the functions we want to make publicly available.
Erlang uses pattern matching for function definitions, so we define each function clause separately. This approach provides a clean way to handle different arities or patterns of arguments.
Erlang is a functional programming language, so it doesn’t require explicit return statements. The value of the last expression in a function is automatically returned.
There are several other features to Erlang functions. One is pattern matching in function heads, which we’ll look at in more detail in future examples.