iex
, short for Interactive Elixir
is the Elixir shell. It allows you to execute your elixir code line-by-line.
iex
allows us to type our code line-by-line, and executes it one line at a time. Typing iex
in your terminal / command prompt will open an interactive elixir shell. Here are some of its features:
iex
also provides some helper functions to make our lives easier. Just type h
and press enter to get a list of all the helper functions. Here’s a few of them:
cd
, clear
, ls
, pwd
, etc. If you’ve ever used a unix-like shell, you know what they do.c
(compile)h
(help)i
(info about last value or given term)recompile
(the entire project) / r
(to recompile a single module)t
(print types for a given module or function)runtime_info
(get info about the current system and runtime)v
(return the value of the nth expression in history, or the last expression by default. Can be negative)🔥 WARNING: Code is evaluated line-by-line in
iex
and not compiled. This means that any benchmarking done in the shell is going to have skewed results, since compilers can optimize the code they’re building, but an interpreter likeiex
can’t do the same. TL;DR: don’t run any profiling or benchmarks in the shell, the results won’t show the true picture.
iex> 1 + 2
3
iex> 3 * 4
12
iex> v(-1)
12
iex> v(1)
3
iex> i
Term
3
Data type
Integer
Reference modules
Integer
Implemented protocols
IEx.Info, Inspect, List.Chars, String.Chars
iex>