Enum slice unexpected output

Why am I randomly getting ‘\n\a’ as output for the following:

Enum.shuffle(1…10) |> Enum.slice(0…1)

1 Like

try typing [7, 10| in the console and You will get ‘\a\n’

but if You type [2,10] You will get [2,10]

somehow, it’s because [7, 10| is equivalent to charlist ‘\a\n’, just not the usual representation.

Have a look at http://elixir-lang.github.io/getting-started/binaries-strings-and-char-lists.html

iex(1)> [7, 7, 7, 10, 10, 10]
iex(2)> [65, 66, 67]

Lots of people get surprised by this…

If elixir can represent a list of int as a list of char, it will, otherwise, it won’t

iex(3)> [65, 66, 67, 200] 
[65, 66, 67, 200]
1 Like

If you have any questions about the output of something, then put i before it in the shell, such as:

iex> i '\n\a'

And hit enter and see what appears. :slight_smile:

1 Like