Elixir Interactive Shell, IEx

Image for post
Image for post

TL;DR

When I evaluate the quality characteristics of a programming language, my first What question is What is the name of the interactive shell. This post is part of the functional language series.

Every modern and popular programming language has an interactive shell. Python and Ruby are some examples. Interactive shells are essential because they enable programmers to do run code that they just wrote. I got on several occasions application to test with code changes that had not even been run once! Developer defended their action because the change was small and he/she run that code in their brain. You have probably been there.

But in developer defense, I must admit that some programming languages make their job very hard to do. In early Java days, there was no interactive shell. Then Jython and JRuby came and made Java developer job much more manageable.

What is the main feature of the interactive shell? It enables the developer to run their code without the need for writing testing code. The developer could check his initial code design straightforward and fast. Testers could also use an interactive shell. Imagine a situation that you, as a tester, could run an interactive shell in the root folder of the application, and without much trouble, you can run any part of the application. For example, with two lines of code, you could insert a thousand test users. Or even better, you could send an email that is a trigger at midnight.

The elixir feature set is based on Ruby, and this is an excellent idea. You run Elixir interpreter by running:

iex --erl "-kernel shell_history enabled"

You could just run

iex

but then you would not have support for command history.

Remember: Two most useful features for any shell, are TAB completion and command HISTORY.

And start using those two features, because THAT IS AUTOMATION that makes you more productive.

What can you run in IEx? You can run all Elixir functions and all library functions that are installed in the project repository from where you run IEx.

Using TAB lets type:

Lis and press
TAB

You will get a list of functions for the module List. If you would like to get hex documentation (this is standard Elixir documentation), you just type:

h(List)

For homework, you should read this page: https://hexdocs.pm/iex/IEx.html. Learning and practicing time is 45 minutes. The remote shells section is entertaining!

And your first Elixir task:

Concatenate these two lists in IEx shell:

Petar, Simun, Juda

Audi, Nissan, Peugeot

You can find instructions using h(List).

Originally published at https://blog.tentamen.eu on April 9, 2020.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store