Defined by name and # of args(arity) hello/1 vs hello/2
Instead of early exits/for invalid args use guards and param pattern matching
Named Fts must be defined inside module, anon fts can be defined anywhere
Named Fts
defmoduleMdodeftransform(myvar,_opts) do#_ means ignore arg8* myvar +3#returns last value automaticallyend#defp for private ftsdefpprivateTransform(v, z \\1) do#default value v *4+ zenddefgetcookie(%{cookie: c} = conn,_params) doIO.inspect(conn)IO.puts("Has cookie #{c}")enddefgetcookie(conn,_params) doIO.puts("No cookie")endend
Recursion
deffactorial(num) doif num <=1do1else result = num *factorial(num -1) resultendend
Loop?
defsum([]), do: 0defsum([h|t]), do: h +sum(t)IO.puts("Sum: #{sum([1,2,3])}")