erlang 错误的函数arity和警告:函数hello_world/0未使用

omtl5h9j  于 2022-12-08  发布在  Erlang
关注(0)|答案(1)|浏览(147)

我刚开始学习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

那么这个问题怎么解决呢,这里面出了什么问题呢?

c3frrgcw

c3frrgcw1#

You wrote:

-export( [ hello_world ]/0 )

It should be:

-export( [ hello_world/0 ] ).

export requires a list, where each element in the list is the function name followed by a slash followed by the arity of the function. A list does not have an arity, which is what you wrote.
Note that when you are just writing test code, it is easier to use:

-compile(export_all).

which will export all functions defined in your module.

相关问题