Elixir Programming Tutorials for beginners in Urdu :Named function in elixir- tutorial- 11

Опубликовано: 01 Март 2026
на канале: How to Install
65
0

Muhammad Aslam Khan waqar
How to install YouTube Chanell
Introduction to modern programming languages in urdu
Elixir Programming Tutorials for beginners :Named function in elixir- tutorial

Named functions are defined with names and using key word def.
Named functions are always defined in a module using key word defmodule and module name.

defmodule modulename do
def function_name(arg1,arg2) do
// code here
end
end

example of named function
defmodule Math do
def sum(a,b) do
a+b
end
end

One liner functions:

defmodule Math do
def sum(a,b), do: a + b
end

Private functions:
In Elixir private functions are defined with keyworld defp.
private functions can only be access from within the module in
which they are defined.
defp sum(a,b) do
a+b
end

In Elixir a function is not just identified by its name,
but by its name and arity. Remember, Everything in Elixir is
an expression.
These are four function with same name.

def sum, do: 0
def sum(a), do: a
def sum(a, b), do: a + b
def sum(a, b, c), do: a + b + c