I'm working through Dave Thomas' Programming Elixir and I'm attempting some examples from the list chapter.
When I'm learning a language I prefer to stay as basic as I can by running <language executable> <script file>
. In this case I'm running elixir reduce.exs
contents of reduce.exs:
require IEx;
defmodule MyList do
def reduce([], memo, _), do: memo
def reduce([head | tail], memo, func) do
IEx.pry
reduce(tail, func.(head, memo), func)
end
end
ExUnit.start()
defmodule MyListTest do
use ExUnit.Case
def test do
assert 10 == MyList.reduce([1,2,3,4], 0, &(&1 + &2))
end
end
IO.puts(MyListTest.test())
When run the console outputs:
Cannot pry #PID<0.70.0> at reduce.exs:9. Is an IEx shell running?
I assume I am completely misunderstanding some core concepts, but I'm not entirely sure what they are.
My expectation is that the program would just drop into an iex
session when it hits the execution of IEx.pry
. Given iex is in the elixir core libraries, I thought the require IEx
would be enough to use pry.
Do I need to use IEx.pry/3
? Do I need to run a separate instance of iex and somehow connect the two nodes together?
Just evaluating the code by running iex reduce.exs
runs the file, but it does not show the test output.
Feel free to correct any and every silly assumption I've made.