Programming Elixir 1.6 - errata (page 227)

def puts(device \\ group_leader(), item) do
        erl_dev = map_dev(device)
        :io.put_chars erl_dev, [to_iodata(item), ?\n]
end

def puts(device \\ :stdio, item) do
        :io.put_chars(map_dev(device), [to_chardata(item), ?\n])
end


The implementation of IO.puts function in page 227 is outdated (elixir/lib/elixir/lib/io.ex at v1.6 · elixir-lang/elixir · GitHub).

The problem is the above code is the introduction of :erlang.group_leader function, which is used later in page 227, but the implementation of IO.puts in Elixir 1.4 and above does not use the :erlang.group_leader function (Use :stdio instead of group_leader() as default device by michalmuskala · Pull Request #5089 · elixir-lang/elixir · GitHub).

By the way,

  • :stdio - a shortcut for :standard_io, which maps to
    the current Process.group_leader/0 in Erlang

(IO — Elixir v1.16.0)

Therefore, although the default device of the IO.puts function has changed to :stdio, the erlang.group_leader() function is still called in Erlang’s io module and the behavior of the IO.puts function was not changed by Use :stdio instead of group_leader() as default device by michalmuskala · Pull Request #5089 · elixir-lang/elixir · GitHub.

2 Likes