1

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

2240
  • 1,547
  • 2
  • 12
  • 30
Bucephalus
  • 291
  • 1
  • 2
  • 9

1 Answers1

3

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.

7stud
  • 46,922
  • 14
  • 101
  • 127
  • Thanks @7stud that was very helpful. Maybe there is an error/3 in OTP 24. Please see what I found on line 26 in this file: https://github.com/erlware/erlware_commons/blob/master/src/ec_cmd_log.erl – Bucephalus May 31 '21 at 06:17
  • The latest version of Nitrogen was released before OTP 24 and i'm using OTP 24. – Bucephalus May 31 '21 at 06:47
  • 1
    @Bucephalus, The comment on line 25 says:`%% Avoid clashing with error/3 BIF added in Erlang/OTP 24`. *The latest version of Nitrogen was released before OTP 24 and i'm using OTP 24.* -- Then you have to downgrade your Erlang or alter the Nitrogen source code to include lines like line 26 wherever error/3 is called. – 7stud May 31 '21 at 19:33
  • Thanks @7stud . I raised this issue in erlang slack and the project manager for Nitrogen said he will address this issue this week. I have plenty of learning to do on Erlang so I will just go onto something else in the mean time and stick with OTP 24. Thanks for your help - it has been very insightful. – Bucephalus Jun 01 '21 at 11:14
  • 2
    The issue has been fixed. It was ultimately that Nitrogen depends on qdate, which depends on erlware_commons (but was bound to an older version of erlware_commons). This has been updated, qdate 0.6.0 is tagged and works with OTP24. – chops Jun 01 '21 at 13:50