May 2018
Intermediate to advanced
412 pages
9h 3m
English
Modules provide namespaces for things you define. We’ve already seen them encapsulating named functions. They also act as wrappers for macros, structs, protocols, and other modules.
If we want to reference a function defined in a module from outside that module, we need to prefix the reference with the module’s name. We don’t need that prefix if code references something inside the same module as itself, as in the following example:
| | defmodule Mod do |
| | def func1 do |
| | IO.puts "in func1" |
| | end |
| | def func2 do |
| | func1 |
| | IO.puts "in func2" |
| | end |
| | end |
| | |
| | Mod.func1 |
| | Mod.func2 |
func2 can call func1 directly because it is inside the same module. Outside the module, you have to use the fully qualified name, Mod.func1 ...
Read now
Unlock full access