HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to ElixirVariablesData TypesOperatorsStringsListsConditions (if / else)Iteration (Enum)Functions
REFERENCE
📖 Overview
🖥️ Output
📦 Variables & Types
🔢 Numbers & Math
✍️ String
📚 List & Enum
🔀 Condition
🧩 Function
Elixir›Data Types

Data Types

integer, float, string, boolean; interpolation (#{}) and text↔number conversion.

Simple enough for a 5-year-old to understand

Basic types and interpolation

You embed a value in a string by writing #{expression} inside double quotes.

Example code
1
number = 7
integer.
Variableinteger.
2
decimal = 3.14
float.
Variablefloat.
3
text = "Elixir"
string.
Variablestring.
4
IO.puts("#{number} #{decimal} #{text}")
7 3.14 Elixir
Output / Input7 3.14 Elixir
VariableOutput / Input
💡 Hint: A variable or expression is written inside #{...}.

About this topic

Elixir's basic types are integers, floats, atoms, strings, lists, tuples, and maps. Integers can grow indefinitely; as long as memory permits, overflow does not occur.

An atom is a constant whose name is its own value. It is heavily used to indicate state: an atom indicating an operation was successful appears everywhere in Elixir code. Atoms compare quickly and improve readability.

The choice between a tuple and a list is important. A tuple holds a fixed number of elements of different types and is fast to access; a list is of variable length and traversed from the beginning. Tuples are used for function returns, and lists for collections.

What you will learn

  • Basic types
  • The role of atoms
  • The difference between tuple and list
  • The map structure
  • Division operators

Who is this for?

  • Those learning Elixir data structures
  • Those who want to understand return value patterns
  • Those surprised by the division result

When to use?

When a function needs to report whether it succeeded or failed, returning a status atom and the value in a tuple is the standard Elixir idiom.

Maps are used when key-based access is required; searching in a list is slow with large data.

Common mistakes

Wrong

IO.inspect 7 / 2
IO.inspect is_integer(7 / 2)

The division operator in Elixir always returns a float; even if two integers are divided, the result is 3.5 and not an integer. There is a separate function for integer division. This behavior differs from many languages and can lead to silent type issues.

Correct

IO.inspect div(7, 2)
IO.inspect rem(7, 2)

Wrong

sonuc = {:ok, 42}
deger = sonuc
IO.puts deger + 1

The entire tuple was bound to a name, but its inner value was not accessed; arithmetic operations cannot be performed directly on a tuple and will result in an error. Pattern matching should be used to extract parts of the tuple; this is the standard way in Elixir.

Correct

sonuc = {:ok, 42}
{:ok, deger} = sonuc
IO.puts deger + 1

Wrong

ayar = %{renk: "blue"}
IO.puts ayar.boyut

Accessing a non-existent key with dot notation raises a KeyError and stops the program. Accessing with brackets returns nil if it doesn't exist. The difference between the two is a conscious design choice: dot notation is for situations where you are certain the key exists.

Correct

ayar = %{renk: "blue"}
IO.inspect Map.get(ayar, :boyut, "default")

Frequently asked questions

What is an atom, and when is it used?

It is a constant whose name is its own value. It is used for status indication, map keys, and configuration options. Warning: atoms are not garbage collected, so generating atoms from user input carries a memory leak risk.

Should I use a tuple or a list?

Use a tuple if the number of elements is fixed and small, and each element has a different meaning; use a list if there is a variable number of elements of the same type. Adding an element to a tuple copies the entire structure, whereas prepending to a list is cheap.

How do I add an element to a map?

Using the Map module's insertion function or update syntax. Both return a new map and do not modify the original. Update syntax only updates existing keys; a function is required to add new keys.

Summary

Integers grow without limit.

The division operator always returns a floating-point result.

Atoms are used to indicate state.

A tuple is fixed-length, while a list is variable-length.

Accessing a non-existent key with a dot raises an error.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code