From 000356946b2f6a4411a0d55d2b6eb68911bb26bb Mon Sep 17 00:00:00 2001 From: Jack Hedaya Date: Mon, 24 Jun 2019 18:24:48 -0400 Subject: [PATCH] add Elixir syntax and return explanations to functions (#27552) * add syntax and return explanations * fix: added language postfix to code fences --- guide/english/elixir/functions/index.md | 33 ++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/guide/english/elixir/functions/index.md b/guide/english/elixir/functions/index.md index 58c172a5f6..e6810ed18d 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