Is this a bug in the Enum.to_list function?

I spent an hour debugging and found this. Is there an explanation for this?

$ iex
Erlang/OTP 25 [erts-13.0.4] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit] [dtrace]

Interactive Elixir (1.13.4) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> Enum.to_list(1..4)
[1, 2, 3, 4]
iex(2)> Enum.to_list(8..12)
'\b\t\n\v\f'
iex(3)>

This is not a bug. What you see is called a charlist - a list of integers interpreted as text.

You can find more info here:

https://hexdocs.pm/elixir/List.html#module-charlists

5 Likes

Thank you for sharing that!

This will soon become a lot less confusing thanks to this change that will be shipped with the next Elixir major release : Convert 'charlists' into ~c"charlists"

3 Likes

Indeed, but we’ll have 50% less traffic here, one should also consider that.

5 Likes

Haha, good one! :grin:
BTW: I was incorrect above, it will be a minor release (1.15.0), not a major, if I understand it correctly. :slight_smile: