Erlang:生成列表中的奇怪字符 [英] Erlang: Strange chars in a generated list

查看:121
本文介绍了Erlang:生成列表中的奇怪字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试通过理解生成列表,在某些时候,我开始看到奇怪的字符串。在这一点上无法解释他们的存在(猜测转义字符是ASCII码 - 但为什么?):

  45> [[round(math:pow(X,2))] ++ [Y] || X < - 列表:seq(5,10),Y < - 列表:seq(5,10)]。 
[[25,5],
[25,6],
[25,7],
[25,8],
[25,9] ,
[25,10],
[36,5],
[36,6],
[36,7],
$ \b ,$ \t,$ \\\

[49,5],
[49,6],
[49,7],
1\b,1\t,1\\\

[64,5],
[64,6],
[64,7] ,
@ \b,@ \t,@ \\\

[81,5],
[81,6],
[81,7],
Q\b,
[...] | ...]


解决方案

在Erlang中,所有字符串只是小整数列表(如C中的chars)。和shell帮助你一点点尝试将任何列表解释为可打印字符串。所以你得到的是数字,它们只是打印出你不会期望的方式。



如果你想改变这种行为,你可以看一下这个答案


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",
 [...]|...]

解决方案

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.

这篇关于Erlang:生成列表中的奇怪字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆