I just started learning Erlang so I coded this as new.erl
:
-module(new).
-export([hello_world]/0).
hello_world()->io:fwrite("Hello\n").
So the function name is hello_world
and it holds Hello
as string.
But whenever I want to run this, I get this result:
new.erl:2: bad function arity
new.erl:3: Warning: function hello_world/0 is unused
error
So how to solve this problem, what's going wrong here ?
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.