What does the slash notation in Elixir mean?

You guessed right that it's the arity of the function. The reason why it's an important information (that is often not included in many languages) is that functions with the same name, but different arity are different functions - an example of that is Enum.reduce/2 and Enum.reduce/3. A function in Elixir is identified by three things: module, name and arity. If any single one of these is different, then you have a different function.

The notation is also mentioned in the Getting Started guide: 1, 2.


From page 2, Basic types of the Getting started documentation:

Note: Functions in Elixir are identified by name and by number of arguments (i.e. arity). Therefore, is_boolean/1 identifies a function named is_boolean that takes 1 argument. is_boolean/2 identifies a different (nonexistent) function with the same name but different arity.

It is also described in Erlang/Elixir Syntax: A Crash Course:

Here we create a module named hello_module. In it we define three functions, the first two are made available for other modules to call via the export directive at the top. It contains a list of functions, each of which is written in the format <function name>/<arity>. Arity stands for the number of arguments.

I might speculate that this tends to be relegated to a side note in Elixir literature because it comes straight from Erlang. Although Erlang knowledge shouldn't be necessary to use Elixir, such omissions are a common mistake when people document software that is derived as Elixir is from Erlang.

Tags:

Elixir