Reputation: 331
I'm following the tutorial on the nitrogen project page: starter tutorial here
and when I point my browser to localhost:8000
it does not work.
I suspect it is something to do with this following the command:
make rel_inets;
/home/david/programming/erlang/nitrogen/nitrogen/rel/nitrogen/lib/erlware_commons/src/ec_cmd_log.erl:160:5: ambiguous call of overridden auto-imported BIF error/3
**-** use erlang:error/3 or "-compile({no_auto_import,[error/3]})." to resolve name clash Compiling /home/david/programming/erlang/nitrogen/nitrogen/rel/nitrogen/lib/erlware_commons/src/ec_cmd_log.erl failed: ERROR: compile failed while processing /home/david/programming/erlang/nitrogen/nitrogen/rel/nitrogen/lib/erlware_commons: rebar_abort make[4]: *** [Makefile:12: compile] Error 1
Does anyone have any idea of what is going wrong? Looks to be some clash between function names. I installed the latest erlang 24.0.1 and I still got the same behaviour. Thanks
Upvotes: 1
Views: 207
Reputation: 48649
Does anyone have any idea of what is going wrong?
Here is an example...Erlang defines a function error/2
, known as a BIF or Built In Function, which can be called like this:
-module(a).
-compile(export_all).
go(X, Y) ->
case X > 10 of
true -> error(bad_arg, [X, Y]);
false -> ok
end,
io:format("hello\n").
In the shell:
4> c(a).
a.erl:2: Warning: export_all flag enabled - all functions will be exported
{ok,a}
5> a:go(1, 2).
hello
ok
6> a:go(11, 2).
** exception error: bad_arg
in function a:go/2
called as a:go(11,2)
7>
Now, look what happens if you define a function also named error/2
in your module:
-module(a).
-compile(export_all).
error(X, Y) ->
io:format("X = ~w, Y = ~w~n", [X,Y]).
go(X, Y) ->
case X > 10 of
true -> error(bad_arg, [X, Y]);
false -> ok
end,
io:format("hello\n").
In the shell:
8> c(a).
a.erl:2: Warning: export_all flag enabled - all functions will be exported
a.erl:9: Warning: ambiguous call of overridden auto-imported BIF error/2
- use erlang:error/2 or "-compile({no_auto_import,[error/2]})." to resolve name clash
{ok,a}
The warning tells you that if you really meant to call erlang's error/2
, then you should preceed the function name with the module name in which the function is defined, namely the erlang
module:
case X > 10 of
true -> erlang:error(bad_arg, [X, Y]);
...or, if you want to call your version of error/2
, then put the module directive:
-compile({no_auto_import,[error/2]}).
at the top of your module:
-module(a).
-compile(export_all).
-compile({no_auto_import,[error/2]}).
error(X, Y) ->
io:format("X = ~w, Y = ~w~n", [X,Y]).
go(X, Y) ->
case X > 10 of
true -> error(bad_arg, [X, Y]);
false -> ok
end,
io:format("hello\n").
11> c(a).
a.erl:2: Warning: export_all flag enabled - all functions will be exported
{ok,a}
Note that the problem in the code is only a warning
, and when I run my program as originally written, erlang calls the version of error/2
defined in my module--not the one in the erlang
module.
The strange thing is: there is no error/3
defined in the erlang module.
Upvotes: 3