Rowland Carlson

Exploring Elixir source code with IEx


Elixir's allows you to find source code directly from IEx.
The open macro will open the given module or module.function/arity in your editor.

open uses ELIXIR_EDITOR by default,
But will fall back to EDITOR if the former isn't available.

open is great for exploring Elixir source code.
For example, how is implemented for lists?

iex()> open

And in my editor:

def map(enumerable, fun) when is_list(enumerable) do, enumerable)

Okay, it makes sense for Elixir to reuse Erlang's implementation of map.
How does Erlang do it?:

iex()> open

And in my editor:

map(F, [H|T]) ->
    [F(H)|map(F, T)];
map(F, []) when is_function(F, 1) -> [].

So Erlang, and therefore Elixir,
uses the [head | tail] syntax to map functions over lists.

If you start your IEx session with Mix:

$ iex -S mix

open can find your project's source code,
And the source code of any downloaded dependencies.

I use the open macro to explore code that I don't understand.
Next time you want to find what a line of Elixir code does,

Do other languages have similar tools for code exploration?

(Thanks to Adi Iyengar for introducing me to this tool.)

Adi Inyengar - Elixir: Open Files with Vim using