diff --git a/guide/english/elixir/functions/index.md b/guide/english/elixir/functions/index.md index 58c172a5f60..e6810ed18d9 100644 --- a/guide/english/elixir/functions/index.md +++ b/guide/english/elixir/functions/index.md @@ -3,11 +3,36 @@ title: Functions --- ## Functions -This is a stub. Help our community expand it. +### Syntax +Functions in Elixir are defined using the def/2 macro: +```elixir +def name(param1, param2) do + # Do stuff +end +``` -This quick style guide will help ensure your pull request gets accepted. +Private functions use the defp/2 macro: +```elixir +defp name(param1, param2) do + # Do stuff +end +``` - +### Returning +Functions in Elixir do not use a return statement. Instead, they take the last expression (no matter how deeply nested in the function) and return that. +```elixir +def add(x, y) do + x + y +end + +def abs(x) do + if x < 0 do + -x + else + x + end +end +``` #### More Information: - ++ Official Module and Function Guide