Introduction to IEx

iex, short for Interactive Elixir is the Elixir shell. It allows you to execute your elixir code line-by-line.

IEx introduction

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:

🔥 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 like iex 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.

Examples

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>