All posts

Elixir Atoms and Integers explained through q&a

This post works best when paired with the Elixir docs for a general overview of Atoms and Integers.

What is an Elixir Atom?

It is an Elixir data type thats value is its own name.

What is an Elixir Atom used for?

They are often used to indicate the result of an operation either as the first value of a tuple or as a standalone response. :ok is often used to indicate a successful operation and :error is used if something goes wrong.

{:ok, result} = some_function()

:ok = some_other_function()

What is special about the values true, false and nil as they relate to atoms?

Each of those data types are atoms. Elixir allows you to skip typing the colon (:) for these atoms. Ex:

true == :true
=> true

nil == :nil
=> true

false == :false
=> true

Which data type represents whole numbers in Elixir Integer or Float?

Integer. Float is used for fractional numbers.

The Kernel and Integer module each define integer functions. What integer functions does the Kernel define?

abs/1, div/2, min/2, max/2, rem/2. These are all arithmetic based functions.

What functions does the Integer module define?

is_env and is_odd. These are most often used as Guards in Elixir.

=> true

=> false

More Elixir Decks:

  1. Tuples
  2. List