mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-08-04 13:57:38 +02:00
Added one more example with guards, fixed typos and identation.
This commit is contained in:
@@ -246,8 +246,8 @@ end
|
|||||||
Math.sum(1, 2) #=> 3
|
Math.sum(1, 2) #=> 3
|
||||||
Match.square(3) #=> 9
|
Match.square(3) #=> 9
|
||||||
|
|
||||||
# To compile our little Math module save it as `math.ex` and use `elixirc`
|
# To compile our simple Math module save it as `math.ex` and use `elixirc`
|
||||||
elixirc math.ex
|
# in your terminal: elixirc math.ex
|
||||||
|
|
||||||
# Inside a module we can define functions with `def` and private functions with `defp`.
|
# Inside a module we can define functions with `def` and private functions with `defp`.
|
||||||
# A function defined with `def` is available to be invoked from other modules,
|
# A function defined with `def` is available to be invoked from other modules,
|
||||||
@@ -278,6 +278,8 @@ end
|
|||||||
|
|
||||||
Geometry.area({:rectangle, 2, 3}) #=> 6
|
Geometry.area({:rectangle, 2, 3}) #=> 6
|
||||||
Geometry.area({:circle, 3}) #=> 28.25999999999999801048
|
Geometry.area({:circle, 3}) #=> 28.25999999999999801048
|
||||||
|
Geometry.area({:circle, "not_a_number"})
|
||||||
|
#=> ** (FunctionClauseError) no function clause matching in Geometry.area/1
|
||||||
|
|
||||||
# Due to immutability, recursion is a big part of elixir
|
# Due to immutability, recursion is a big part of elixir
|
||||||
defmodule Recursion do
|
defmodule Recursion do
|
||||||
|
Reference in New Issue
Block a user