列表中的数字打印为“\f”

Number in list printed as "\f"

我正在尝试学习 Erlang,但当我 运行 遇到问题时,我只学了运算符:

5> TheList = [2,4,6,8]. 
[2,4,6,8]
6> 
6> [N || N <- TheList, N rem 3 =:= 0]. 
[6]
7> 
7> TheList. 
[2,4,6,8]
8> 
8> [2*N || N <- TheList, N rem 3 =:= 0]. 
"\f"
9> 

为什么上次操作得到"\f"?不应该是[12]吗? "\f" 是什么意思?谢谢

解释here例如:

Erlang has no separate string type. Strings are usually represented by lists of integers (and the string module of the standard library manipulates such lists). Each integer represents the ASCII (or other character set encoding) value of the character in the string. For convenience, a string of characters enclosed in double quotes (") is equivalent to a list of the numerical values of those characters.

您可以使用 io:format 函数:

1> io:format("~w~n", [[2*N || N <- [2,4,6,8], N rem 3 =:= 0]]).
[12]

或使用从 Erlang R16B 开始的 shell:strings/1 函数禁用此行为:

2> shell:strings(false).
true
3> [2*N || N <- [2,4,6,8], N rem 3 =:= 0].
[12]

正如@Atomic_alarm 在评论中提到的,这是由于 erlang 使用字符串语法而不是整数列表打印出答案。默认值是true,这里看到[12],你要把值设置成false。它的文档是 here.