Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I disable printing lists of small integers as strings in Erlang shell?

The Erlang shell "guesses" whether a given list is a printable string and prints it that way for convenience. Can this "convenience" be disabled?

like image 355
Alexey Romanov Avatar asked Feb 27 '10 16:02

Alexey Romanov


2 Answers

I don't know if it's possible to change the default behavior of the shell, but you can at least format your output correctly, using io:format.

Here is an example:

1> io:format("~p~n", [[65, 66, 67]]).
"ABC"
ok
2> io:format("~w~n", [[65, 66, 67]]).
[65,66,67]
ok

And since the shell is only for experimenting / maintenance, io:format() should be at least enough for your real application. Maybe you should also consider to write your own format/print method, e.g. formatPerson() or something like that, which formats everything nicely.

like image 188
tux21b Avatar answered Oct 19 '22 04:10

tux21b


You can disable such behavior with shell:strings/1 function starting with Erlang R16B.

Just remember that this is option global to all node shells, and it might be wise to set it back after finishing playing is shell in longer living nodes.

like image 42
mpm Avatar answered Oct 19 '22 03:10

mpm