I'm currently learning Elixir and going through all exercises in the "Programming Elixir 1.6" book. As exercises itself are pretty simple, I struggle to understand something concerning outputs.
At the end of chapter 5, I'm asked to rewrite those lines using anonymous functions :
Enum.map [1, 2, 3, 4], fn x -> x + 2 end
Enum.each([1, 2, 3, 4], fn x -> IO.inspect x end
So I wrote this :
Enum.map([1, 2, 3, 4], &(&1 + 2))
Enum.each([1, 2, 3, 4], &IO.inspect/1)
But after running this my output was only from the inspect :
λ elixir functions-5.exs
1
2
3
4
So I added some IO.puts
in here :
IO.puts Enum.map([1, 2, 3, 4], &(&1 + 2))
IO.puts Enum.each([1, 2, 3, 4], &IO.inspect/1)
And the output was really strange, to say the least :
λ elixir functions-5.exs
╚╝║═
1
2
3
4
ok
After trying some alternative syntax and using variables in between calls, I tried to execute those lines directly into Interactive Elixir :
iex(2)> Enum.map([1, 2, 3, 4], &(&1 + 2))
[3, 4, 5, 6]
It works fine this way! Why?
iex(1)> IO.puts Enum.map([1, 2, 3, 4], &(&1 + 2))
╚╝║═
:ok
IO.puts
seems to break formatting again, why again?
What am I missing? why the different context of executions doesn't have the same output?
To summarize my overall question: Whiskey Tango Foxtrot ???