What does the double backslash mean in a function parameter in Elixir?

It specifies a default value.

Function arguments defined using \\ after the argument name are providing an optional default. So if loop/2 is called, the first argument will be the pid returned from self(). If loop/3 is called, then you would specify a pid.

Let’s take another (trivial) example:

math.ex

defmodule Math do   
  def add(a \\ 2, b) do
    a + b   
  end 
end

iex (1)> c("math.ex")

iex (2)> Math.add(1, 8) # add/2, because you are matching 1 to `a`.
9

iex (3)> Math.add(8) # add/1, because `a` is by default matched to 2.
10

Leave a Comment

deneme bonusu veren sitelerbahis casinomakrobetceltabetpinbahispolobetpolobet girişpinbahis girişmakrobet girişpulibet girişmobilbahis girişkolaybet giriş