[13] and other numbers output Escape characters instead of one number lists. Why?


I have a function which at some point should return a list of values. As expected, the answer is [13] but instead of yielding [13] as a list the function yields '\r'.

I have tried checking it in the shell. Got the same result:

iex(1)> [13]

Have tried a bunch of functions, like Enum.flatten([],[13]) or [[13]] but they give the same results.
What is this about?

Thank you!

1 Like

Hello and welcome,

‘\r’ is equivalent to [13], just not the same notation.

Don’t worry, this happens to everyone…

1 Like

Is there any way to just get a list with the number 13? :))

There is an option with inspect…

iex> [13] |> IO.inspect(charlists: :as_list)

You might also try this…

iex> 'hello world' |> IO.inspect(charlists: :as_list)
[104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]

If the list is kind of printable, it will use charlist instead of the normal list. That’s what You see…

1 Like

Thank you! :blush: