Erlang: Output Problem

2019-05-26 14:51发布

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]

2条回答
冷血范
2楼-- · 2019-05-26 15:30

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.

查看更多
爷的心禁止访问
3楼-- · 2019-05-26 15:49

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"
查看更多
登录 后发表回答