函数参数错误和警告:函数 hello_world/0 未使用

Bad function arity and warning: function hello_world/0 is unused

我刚开始学习 Erlang,所以我将其编码为 new.erl:

-module(new).
-export([hello_world]/0).
 hello_world()->io:fwrite("Hello\n").

所以函数名称是 hello_world 并且它保存 Hello 作为字符串。

但是每当我想要 运行 这个时,我都会得到这个结果:

new.erl:2: bad function arity
new.erl:3: Warning: function hello_world/0 is unused
error

那么如何解决这个问题,这里出了什么问题?

您写道:

 -export( [ hello_world ]/0 )

应该是:

 -export( [ hello_world/0 ] ).

export 需要一个列表,其中列表中的每个元素都是函数名称后跟一个斜杠,然后是函数的元数。 list没有arity,这是你写的。

注意,当你只是写测试代码时,使用起来更容易:

-compile(export_all).

这将导出您的模块中定义的所有函数。