O'Reilly logo

Programming Elixir by Dave Thomas

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Module Names: Elixir, Erlang, and Atoms

When we write modules in Elixir, they have names such as String or PhotoAlbum. We call functions in them using calls such as String.length("abc").

What’s happening here is subtle. Internally, module names are just atoms. When you write a name starting with an uppercase letter, such as IO, Elixir converts it internally into an atom called Elixir.IO.

 
iex>​ is_atom IO
 
true​​​
 
iex>​ to_string IO
 
"Elixir.IO"​​​
 
iex>​ :​"Elixir.IO"​ === IO
 
true

So a call to a function in a module is really an atom followed by a dot followed by the function name. And, indeed, we can call functions like this:

 
iex>​ IO.puts 123
 
123
 
:ok​​
 
iex>​ :​"Elixir.IO"​.puts 123
 
123
 
:ok

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required