Erlang: Output Problem

2019-05-26 15:08发布

问题:

In my erlang web application, there is a list, which contains integers to be printed on the web page. But when the script executes, it prints this, instead of actual list,

Please look at this Image showing characters for unicode codepoint 1, 1, 2, 3, 5, 8, whitespace, codepoint 15

How to format this to gain what I want? Target list is [1, 1, 2, 3, 5, 8, 13, 15]

回答1:

You should do this:

P = [1, 1, 2, 3, 5, 8, 13, 15],
Show_on_page = io_lib:format("~p",[P]),
Show_on_page.

This will represent any Erlang term on the web page the way you want to see it.



回答2:

You Web presentation probably like the values more converted to string (lists).

1> [ integer_to_list(I) || I <- [1,1,2,3,5,8,13,15] ].
["1","1","2","3","5","8","13","15"]

Maybe join them as well depending on your formatting.

2> string:join([ integer_to_list(I) || I <- [1,1,2,3,5,8,13,15] ],",").
"1,1,2,3,5,8,13,15"