Adds clarification for functions with multiple clauses.

This commit is contained in:
Chris Zimmerman 2018-10-08 12:17:24 -04:00
parent 215d688c06
commit b230fbd52f

View File

@ -287,7 +287,11 @@ end
PrivateMath.sum(1, 2) #=> 3 PrivateMath.sum(1, 2) #=> 3
# PrivateMath.do_sum(1, 2) #=> ** (UndefinedFunctionError) # PrivateMath.do_sum(1, 2) #=> ** (UndefinedFunctionError)
# Function declarations also support guards and multiple clauses: # Function declarations also support guards and multiple clauses.
# When a function with multiple clauses is called, the first function
# that satisfies the clause will be invoked.
# Example: invoking area({:circle, 3}) will call the second area
# function defined below, not the first:
defmodule Geometry do defmodule Geometry do
def area({:rectangle, w, h}) do def area({:rectangle, w, h}) do
w * h w * h