tansan
September 5, 2022, 7:31am
1
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:
Preamble
This Wiki is intended to be a community-maintained (see the Contribution Guidelines if interested) resource of common “gotchas” (unexpected issues) that beginners to Elixir might experience.
The main intended audience is programmers used to other languages, who come to Elixir and find themselves confused by some particularities of the language and its ecosystem. We also hope it can be used by experienced Elixir programmers as a tool for answering questions and guiding beginners - a qu…
https://hexdocs.pm/elixir/List.html#module-charlists
5 Likes
tansan
September 5, 2022, 7:38am
3
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
Sebb
September 5, 2022, 10:02am
5
Indeed, but we’ll have 50% less traffic here, one should also consider that.
5 Likes
Haha, good one!
BTW: I was incorrect above, it will be a minor release (1.15.0), not a major, if I understand it correctly.