Elixirの対話モードでデバッグの動作を確認してみた

# 概要
Elixirの対話モードでデバッグの動作を確認してみました。以下のページを参考にしました。

https://dev.to/gumi/elixir-21--21a1

# 対話モードで実行
以下のコマンドを実行しました。
```
$ iex
Erlang/OTP 24 [erts-12.2.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [jit]

Interactive Elixir (1.12.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> defmodule Example do
...(1)> def square_sum(first, last) do
...(1)> for i <- first..last do
...(1)> i
...(1)> end
...(1)> |> IO.inspect
...(1)> |> Enum.map(fn x -> x * x end)
...(1)> |> IO.inspect
...(1)> |> Enum.sum
...(1)> end
...(1)> end
{:module, Example,
 <<70, 79, 82, 49, 0, 0, 7, 32, 66, 69, 65, 77, 65, 116, 85, 56, 0, 0, 1, 8, 0,
   0, 0, 27, 14, 69, 108, 105, 120, 105, 114, 46, 69, 120, 97, 109, 112, 108,
   101, 8, 95, 95, 105, 110, 102, 111, 95, ...>>, {:square_sum, 2}}
iex(2)> Example.square_sum(1, 5)
[1, 2, 3, 4, 5]
[1, 4, 9, 16, 25]
55
iex(3)> defmodule Example do
...(3)> def square_sum(first, last) do
...(3)> IO.inspect binding()
...(3)> for i <- first..last do
...(3)> i
...(3)> end
...(3)> |> IO.inspect(label: "before")
...(3)> |> Enum.map(fn x -> x * x end)
...(3)> |> IO.inspect(label: "after")
...(3)> |> Enum.sum
...(3)> end
...(3)> end
warning: redefining module Example (current version defined in memory)
  iex:3

{:module, Example,
 <<70, 79, 82, 49, 0, 0, 7, 208, 66, 69, 65, 77, 65, 116, 85, 56, 0, 0, 1, 19,
   0, 0, 0, 29, 14, 69, 108, 105, 120, 105, 114, 46, 69, 120, 97, 109, 112, 108,
   101, 8, 95, 95, 105, 110, 102, 111, 95, ...>>, {:square_sum, 2}}
iex(4)> Example.square_sum(1, 5)
[first: 1, last: 5]
before: [1, 2, 3, 4, 5]
after: [1, 4, 9, 16, 25]
55
iex(5)> defmodule Example do
...(5)> def square_sum(first, last) do
...(5)> require IEx; IEx.pry
...(5)> for i <- first..last do
...(5)> i
...(5)> end  
...(5)> |> Enum.map(fn x -> x * x end)
...(5)> |> Enum.sum
...(5)> end
...(5)> end
warning: redefining module Example (current version defined in memory)
  iex:5

{:module, Example,
 <<70, 79, 82, 49, 0, 0, 17, 20, 66, 69, 65, 77, 65, 116, 85, 56, 0, 0, 1, 20,
   0, 0, 0, 29, 14, 69, 108, 105, 120, 105, 114, 46, 69, 120, 97, 109, 112, 108,
   101, 8, 95, 95, 105, 110, 102, 111, 95, ...>>, {:square_sum, 2}}
iex(6)> Example.square_sum(1, 5)
Break reached: Example.square_sum/2 (iex:7)
pry(1)> first
1
pry(2)> last
5
pry(3)> respawn

Interactive Elixir (1.12.2) - press Ctrl+C to exit (type h() ENTER for help)
55
iex(1)> 
```

# ファイルを作ってコンパイル
ファイルを作成しました。
```example.ex
defmodule Example do
  def square_sum(first, last) do
    for i <- first..last do
      i
    end
    |> Enum.map(fn x -> x * x end)
    |> Enum.sum
  end
end
```
コンパイルしました。
```
$ elixirc example.ex
```
以下のコマンドを実行しました。
```
$ iex
Erlang/OTP 24 [erts-12.2.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [jit]

Interactive Elixir (1.12.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> break! Example.square_sum/2
1
iex(2)> Example.square_sum(1, 5)
Break reached: Example.square_sum/2 (example.ex:2)

    1: defmodule Example do
    2:   def square_sum(first, last) do
    3:     for i <- first..last do
    4:       i

pry(1)> first
1
pry(2)> last
5
pry(3)> whereami
Location: example.ex:2

    1: defmodule Example do
    2:   def square_sum(first, last) do
    3:     for i <- first..last do
    4:       i

    Example.square_sum/2

pry(4)> whereami 9
Location: example.ex:2

    1: defmodule Example do
    2:   def square_sum(first, last) do
    3:     for i <- first..last do
    4:       i
    5:     end
    6:     |> Enum.map(fn x -> x * x end)
    7:     |> Enum.sum
    8:   end
    9: end
    Example.square_sum/2

pry(5)> respawn

Interactive Elixir (1.12.2) - press Ctrl+C to exit (type h() ENTER for help)
55
iex(1)> break! URI.decode_query/2
2
iex(2)> URI.decode_query("percent=oh+yes%21", %{"starting" => "map"})
Break reached: URI.decode_query/2 (/build/elixir-lang-YztK4b/elixir-lang-1.12.2.dfsg/lib/elixir/lib/uri.ex:174)
pry(1)> query
** (UndefinedFunctionError) function :erl_eval.query/0 is undefined or private

pry(1)> map
** (UndefinedFunctionError) function :erl_eval.map/0 is undefined or private

pry(1)> respawn

Interactive Elixir (1.12.2) - press Ctrl+C to exit (type h() ENTER for help)
%{"percent" => "oh yes!", "starting" => "map"}
iex(1)> :debugger.start()
** (UndefinedFunctionError) function :debugger.start/0 is undefined (module :debugger is not available)
    :debugger.start()
iex(1)> :int.ni(Example)
** (UndefinedFunctionError) function :int.ni/1 is undefined (module :int is not available)
    :int.ni(Example)
iex(1)> :int.break(Example, 6) 
** (UndefinedFunctionError) function :int.break/2 is undefined (module :int is not available)
    :int.break(Example, 6)
iex(1)> Example.square_sum(1, 5)
55
iex(2)> :observer.start()
** (UndefinedFunctionError) function :observer.start/0 is undefined (module :observer is not available)
    :observer.start()
iex(2)> 
```

# まとめ
何かの役に立てばと。