def (module function)
Named function.
Syntax
defmodule M do def name(p) do ... end end
Description
Named functions are defined with def inside a module. Called with Module.function(args) (no dot). The last expression is returned automatically.
Example
Loading editor…
Expected output
17
When to use?
Dividing the program into modules and reusable functions.