Short Elixir note — Module and Atom

tngan
tngan
Sep 8, 2018 · 1 min read

In Elixir world, I almost get inspired every day. I will keep writing a short note to explain some of the interesting topics from day to day.

Module as an atom ?

We always call a module function with the following format.

defmodule Hi do
def my_name_is(), do: "tngan"
end
Hi.my_name_is() # "tngan"

As we know, Elixir has a great interoperability with Erlang libraries. Therefore, we can call the function with an atom. It might confuse the newbie that the type of:string.

:string.trim "test             " # output is "test"

In fact, we can use iex to check this out.

Info of our Hi module and :string module

Yeah, so the module is an atom with a prefix Elixir in order to differentiate the module from Erlang libraries. In other words, the Elixir module function can be called via:

:"Elixir.Hi".my_name_is() # "tngan"
tngan

Written by

tngan

a minimalist uses code to light up the sky

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade