0

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?

Peer Stritzinger
  • 8,232
  • 2
  • 30
  • 43
shubhamagiwal92
  • 1,362
  • 4
  • 25
  • 47

1 Answers1

2

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.

J. Sebio
  • 114
  • 1
  • 1
  • 8