Importance of . in the Anonymous Functions in Elixir functional programming

154 views Asked by At

I am new to Elixir. While going through Elixir School online in the functions section, I found Anonymous Functions. In Anonymous Functions, the function definition is as follows

iex> sum = fn (a, b) -> a + b end
iex> sum.(2, 3)
     5

My question is what is the importance of . used while calling Anonymous functions?

1

There are 1 answers

0
J. Sebio On BEST ANSWER

The use of the . is very easy to explain.

Explaining it with your example, you have to the . to indicate to the compiler that sum is a identifier that describes a variable that contain a reference to function and not a identifier that describes a variable with a normal data type or a named function.

So, when you see a function being called using dot syntax, you will know its an anonymous function, rather than trying to find the regular function definition.