Tips and Tricks for Working in IEx

iex

#1

Anyone have some tips for running functions or other things you commonly do in iex?

I am trying to figure out how to run a do loop with multiple lines and can’t figure it out.

It’s easy to do one line like this:

iex> for i <- 0..100, i > 0, do: WHAT YOU WANT TO DO

Also how would one use the Rails equivalent of Byebug?


#2
iex(2)> Enum.map([1,2,3], fn a ->
...(2)>   IO.puts a
...(2)>   a * a
...(2)> end)

Just writing them out as you would do in an editor is sufficient.

It would work for a comnprehension as well, just hit enter after do (no cologn!).


I have no clue what Byebug is, so can’t help you with that.


#3

Byebug… i don’t know how much it can do, because I found Pry much superior in Ruby world, and there is Pry in Elixir world too, anyway, here’s little article that I think will be helpful http://blog.plataformatec.com.br/2016/04/debugging-techniques-in-elixir-lang/


#4

I renamed the topic and moved to a generic section as it’s not Phoenix specific.

The first thing I do is enable shell history: https://hexdocs.pm/iex/IEx.html#module-shell-history


#5

:wave:

Not sure about other text editors, but in spacemacs with alchemist it’s possible to send snippets of code from a buffer into the repl, so I use that sometimes. Although most often I just edit and save the module’s source code and rely on code reloading (with exsync, for example) to also update the loaded modules in the repl.

For “debugging” I tend to use tracing, like rexbug. I haven’t found a way to do step-through debugging sensibly with elixir …