Strang difference when calling IO.puts in a function inside (depending on device)

Hi there

it is either and probably just me being stupid (label as bug and wontfix :wink:) or just maybe it’s a bug in Elixir

iex(21)> filen
iex(22)>, [:write], fn f -> IO.puts(f, ["hello", [" ", ["world"]]]) end)
{:ok, :ok}
iex(23)>! filen
"hello world\n"

looks good to me, however

iex(24)>, [:write], fn f -> IO.puts(f, ["hello", [" ", ["world"]]]) end)
** (FunctionClauseError) no function clause matching in IO.chardata_to_string/1

    The following arguments were given to IO.chardata_to_string/1:

        # 1

    Attempted function clauses (showing 2 out of 2):

        def chardata_to_string(string) when is_binary(string)
        def chardata_to_string(list) when is_list(list)

    (elixir 1.10.3) lib/io.ex:572: IO.chardata_to_string/1
    (elixir 1.10.3) lib/file.ex:1381:
    (elixir 1.10.3) lib/file.ex:1414:

Could be normal although slightly unpratical behavior, however:

iex(24)> IO.puts(:stdio, ["hello", [" ", ["world"]]])
hello world

And yes, I forgot

Erlang/OTP 23 [erts-11.0.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]

Interactive Elixir (1.10.4) - press Ctrl+C to exit (type h() ENTER for help)

So what did just happen in iex(24)?

Help’s appreciated


reproduced with strings instead of chardata BTW

The issue is that expects a Path.t() as first argument and you are passing in an atom.


I would need a reminder of RTF, thank’s a lot, how can I have missed that? Oh please be polite and consider this a rethorical question.

Thx for your quick response

Now would it not be great if returned :stdio though?

(Quite an enormous amount of work I guess)

Well never mind, what I really forgot is that File is not IO :cry:

That wouldn’t be consistent. returns an io_device which is in fact a pid you can use with the functions from the IO module (except in raw mode). :stdio is a shortcut in the IO module which maps to the group leader’s pid. It has no meaning in the context of the File module.

Having pids representing io_devices means that in a distributed setting you can do things such as have a node write to a file that is on another node transparently.

Yeah I realised that, I should not post before thinking, and that’s why I do not post, normally, what about
test driven posting?

Thx for your time again