Erlang: Strange chars in a generated list

烈酒焚心 提交于 2019-12-07 20:33:37

问题


Trying to generate a list through comprehension and at some point I start seeing strange character strings. Unable to explain their presence at this point (guessing the escape chars to be ASCII codes - but why?):

45> [[round(math:pow(X,2))] ++ [Y]|| X <- lists:seq(5,10), Y <- lists:seq(5,10)].                                     
[[25,5],
 [25,6],
 [25,7],
 [25,8],
 [25,9],
 [25,10],
 [36,5],
 [36,6],
 [36,7],
 "$\b","$\t","$\n",
 [49,5],
 [49,6],
 [49,7],
 "1\b","1\t","1\n",
 [64,5],
 [64,6],
 [64,7],
 "@\b","@\t","@\n",
 [81,5],
 [81,6],
 [81,7],
 "Q\b",
 [...]|...]

回答1:


In Erlang all strings are just list of small integers (like chars in C). And shell to help you out a little tries to interpret any list as printable string. So what you get are numbers, they are just printed in a way you would not expect.

If you would like to change this behaviour you can look at this answer.



来源:https://stackoverflow.com/questions/26425435/erlang-strange-chars-in-a-generated-list

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