IO.puts output meaning

What does the output of this IO.puts mean?

IO.puts(a=1)
1
:ok

but

a = 1
1

When executing in iex:

iex> a = 1
1

You see the result of the operation, which is 1.

When executing:

iex> IO.puts(a=1)
1
:ok

You see the result of the operation, which is :ok, but you also see 1 that you printed (wrote to :stdio).

In the docs, you can read that IO.puts/2 returns :ok in case of success.
https://hexdocs.pm/elixir/IO.html#puts/2

2 Likes

You should also notice that the 1 is plain colored and the :ok is colored by elixir’s pretty print, indicating it’s a evaluation output and not a print to screen, which can only be colored explicitly.

1 Like