Return 在 Erlang 中删除后出现奇怪的列表,谁能解释一下?

Return of a list is coming out odd after deletion in Erlang, can anyone explain?

所以我遇到了这种奇怪的情况,我从列表中删除了一个元素 5,但是当我 return 这个新列表时,输出很奇怪。到目前为止,我已经对其进行了测试,并且有多种情况会发生这种情况,不仅仅是在我下面的代码中,还有这种情况不会发生但仍然非常相似的情况。一个打印良好的例子是当我删除 10 或 12 而不是 5 时。所以我通过执行 lists:member() 知道 Newlist 中确实存在 10,当我执行 io:format() 时,列表正确显示。但是当我最后 return Newlist 时,我得到“\n\f”作为输出,我不完全理解为什么。我相信这与列表不是标准语法有关,如 io:format 的文档中所述,控制序列 ~w 的作用:

"Writes data with the standard syntax. This is used to output Erlang terms. Atoms are printed within quotes if they contain embedded non-printable characters. Atom characters > 255 are escaped unless the Unicode translation modifier (t) is used. Floats are printed accurately as the shortest, correctly rounded string."

关于为什么会发生这种情况的任何想法以及任何人可能拥有的解决方案,以便在 returned 列表时,它只是一个 [10,12]?

的简单列表
unload_shiptest3(Container) ->
   Q = [5,10,12],
   Newlist = Q -- [Container],
   R = lists:member(10,Q),
   io:format("~w~n",[Newlist]),
   Newlist.

"/n/f" 和 [10,12] 是相同的列表,您可以在 shell:

中轻松验证
9> "\n\f" = [10,12].
"\n\f"

不会抛出错误。

在您的代码中,使用显式格式 ~w,您会得到未解释的列表:[10,12]。但是如果你在 shell 中测试你的函数,它会使用漂亮的打印格式打印它。结果仅包含 ASCII 字符,因此将其打印为字符串 "\n\f".

当您测试删除元素 10 时,生成的列表包含 5,它未被解释为可打印字符,打印结果正是您所期望的 [5,12]

我认为有一种方法可以让 shell 避免使用漂亮的打印,如果我检索到它,我会进行编辑。