Kernel.inspect output in iex

Here is the output I don’t understand:

iex(17)> IO.puts(inspect "hello")
"hello"
:ok

According to the Kernel docs,

inspect(item, opts \\ [])
Inspects and writes the given item to the device.

Okay, so IO.puts() has to evaluate it’s argument before executing, therefore inspect "hello" should output hello (in some form), and because inspect() returns its argument, that means this line:

IO.puts(inspect "hello")

becomes:

IO.puts("hello")

which outputs:

"hello"
:ok

So, I think the output of:

 IO.puts(inspect "hello")

should be:

"\"hello\""
"hello"
:ok
iex(1)> value = "hello"
"hello"
iex(2)> quoted = "\"#{value}\""
"\"hello\""
iex(3)> quoted === inspect(value)
true
iex(4)> IO.puts(value)
hello
:ok
iex(5)> IO.puts(quoted)
"hello"
:ok
iex(6)> IO.puts(inspect(value))
"hello"
:ok
iex(7)>

Sorry peerreynders, I don’t understand what your code is supposed to demonstrate. I don’t understand why line 6 doesn’t output 2 things plus the return value of :ok, so 3 things total. I’m not concerned about how things are quoted–what I don’t understand is the number of things that iex outputs on line 6.

is incorrect

ex(1)> inspect("hello")
"\"hello\""
iex(2)> IO.puts("\"hello\"")
"hello"
:ok
iex(3)>

This code:

iex(2)> IO.puts("\"hello\"")
"hello"
:ok

outputs 2 things. But, according to the docs, which I quoted, inspect() outputs something. Therefore by deductive reasoning, if IO.puts() outputs 2 things in iex, then according to the docs, the line:

IO.puts(inspect "hello")

has to output 3 things.

Kernel.inspect/2 isn’t IO.inspect/2

iex(1)> IO.puts(IO.inspect("hello"))
"hello"
hello
:ok
iex(2)>
2 Likes

inspect/2 doesn’t output anything. IO.inspect/2 however does.

3 Likes

Sorry, my fault. I got the modules mixed up. Never mind. :frowning: