Erlang: Output Problem

浪尽此生 提交于 2019-12-07 22:58:10

问题


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"


来源:https://stackoverflow.com/questions/4595361/erlang-output-problem

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!