iex: the interactive shell

Start iex

iex is the interactive Elixir shell: a prompt that runs each line the moment you press Enter. Open it with one command and you will see a banner plus a prompt waiting for input.

Open the interactive shell

iex

Interactive Elixir - press Ctrl+C to exit (type h() ENTER for help)

iex>

Try expressions

Inside iex every line is a small program. Type an expression, press Enter, and iex prints the result right away.

iex> 1 + 2

3

iex> "hi " <> "there"

hi there

iex> name = "Ada"

"Ada"

Nothing is saved to a file here, so iex is perfect for quick checks. When an idea works in iex, copy it into a script file later.

h and tab completion

iex completes code for you. Type the first letters of a word and press Tab twice: iex shows or finishes the matching names.

The helper documents one function at a time:

Read the help for one function

h(Enum.map)

Read the printed text, then press Enter to get a fresh prompt.

Exit

When you are done experimenting, leave the shell and return to the normal terminal. Press Ctrl+C twice, or halt the virtual machine from inside iex:

Halt the virtual machine from inside iex

System.halt()

Next: Your first script

Article author: Arthur Isaev