jonnifyelixir
F3 · The Elixir Language / F3.01 · values

F3 · Foundations · module 1

Values, types & IEx

Every program is built from a small set of values. Before any syntax for combining them, it is worth knowing what they are and how to inspect them — and the fastest way to do that is the shell, where you type a value and Elixir tells you what it is.

F1 and F2 treated values abstractly: a function maps inputs to outputs, immutable data is never edited in place. This module makes those values concrete. Elixir has integers and floats, atoms and booleans, strings, lists, tuples, and maps — and a shell, IEx, for examining each one as you go.

The shell

IEx — Interactive Elixir — is a prompt where you type an expression and see its result. It is the first tool to reach for: there is no faster way to check what a value is or how a function behaves. Inside IEx, h/1 prints documentation and i/1 describes any term.

iex> 40 + 2
42
iex> "hello" <> " world"
"hello world"
# i/1 describes any value; h/1 prints docs

The values

Select a value to see its type, the predicate that recognises it, and how IEx describes it with i/1.

The built-in values · select one


      

A value's type is never in doubt: ask the shell. i/1 names it, and an is_* predicate confirms it — the habit that makes pattern matching, next, feel natural.

The eight you meet first

integer
whole numbers of arbitrary precision — 42, 1_000_000.
float
64-bit floating point — 3.14.
atom
a constant whose name is its value — :ok, :error.
boolean
true and false — which are themselves atoms.
string (binary)
UTF-8 text, stored as a binary — "hi".
list
a linked list — cheap to prepend, linear to index — [1, 2, 3].
tuple
a fixed-size group, fast to index — {:ok, value}.
map
a key-value structure, the workhorse collection — %{a: 1}.

F1 & F2 · abstract values

A value is whatever a function maps to or from — immutable, inspectable, never edited in place.

F3 · concrete types

Those values have names and predicates: integer, atom, list, tuple, map — each checkable in IEx.

Next: F3.02 — Pattern matching & the match operator, where = turns out to be a match rather than assignment. Return to the chapter overview for the full path.

References

Primary sources for this lesson, and where it connects in the course.

Sources

Related in this course