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

前端 未结 7 1011

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

7条回答
  •  离开以前
    2020-11-27 21:26

    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.

提交回复
热议问题