IEx and Mix Notes


Further side-quest to become comfortable with IEx/mix/dbg/pry. Learning commandline debugging since I’ve not been able to figure out how to launch a debuggable commandline program from VSCode.

IEx

A quick introduction to IEx functionality: 8 + 1 things….

# Start and run the mix script:
iex -S mix

# Run specific function
iex -S mix run -e "Issues.CLI.run(['arg1', 'arg2'])"

# Recompile changed mix project files.
recompile

Mix

# Create new project tree
mix new project_name

mix test

# Show dependencies
mix deps

# Fetch dependencies
mix deps.get

# Run Chapter 13 exercise:
mix run -e 'Issues.CLI.run(["rgacote", "ProgrammingElixirExercises"])'

Debugging

  1. Use the Elixir dbg() statement.

  2. IEx drops you into pry.

    # See variable bindings
    binding()
    
    # Execution stack
    whereami()
  3. Cannot continue after a piped dbg() because it returns ``:ok`.

  4. Use break! from IEx.

    break! Issues.CLI.run/1

  5. Pry is not a debugger. You can only examine local information.

Creating a CLI

Builds the commandline interface in the home directory.

  1. Add a main(argv) function to the CLI module.

  2. Add line to mix.exs def project section:

    escript: [main_module: Issues.CLI],

  3. Build:

    mix escript.build

All notes and comments are my own opinion. Follow me at @rgacote@genserver.social