Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Erlang lists with single numbers over 8?

Tags:

list

erlang

In some weird way all the numbers over 8, single, in a list becomes some kind of ASCII?

[8] -> ["\b"]

Please try to help me with this one :)

like image 857
Johnny Avatar asked Dec 22 '22 09:12

Johnny


2 Answers

String is not a data type in Erlang, it's just a list of integers. But Erlang shell try to display lists as strings if possible:

1> S = [65, 66, 67, 68, 69, 70].
"ABCDEF"
2> S = "ABCDEF".
"ABCDEF"
3> io:write(S).
[65,66,67,68,69,70]ok
4> [65, 66].
"AB"
5> [65, 66, 1].
[65,66,1]
like image 78
hdima Avatar answered Jan 01 '23 21:01

hdima


Print it with ~w instead of ~p, and your issue should go away.

~p tries to interpret the elements in the list as ASCII. ~w does not.

like image 29
EvilTeach Avatar answered Jan 01 '23 22:01

EvilTeach