I have the following Erlang code running on Eclipse Erlide:
%% @author gakuo
%% @doc @todo Add description to links.
-module(links).
%% ====================================================================
%% API functions
%% ====================================================================
-export([start/1, test/1,middle/2]).
%% ====================================================================
%% Internal functions
%% ====================================================================
start(N)->
register(first,spawn_link(links,make,[N-1])).
make(0)->
last();
make(N)->
middle(spawn_link(links,make,[N-1]),N).
middle(Next,N)->
receive
Msg->
Next ! Msg,
io:format("Process ~w received ~w~n",[N,Msg]),
middle(Next,N)
end.
last()->
receive
stop->
io:format("last process now exiting ~n", []),
exit(finished);
Msg->
io:format("last process received ~w ~n", [Msg]),
last()
end.
test(Msg)->
first ! Msg.
I run it as follows:
links:start(3).
At this point, I get the following error:
Eshell V9.0.4
(processlinking@GAKUO)1> links:start(3).
** exception exit: undef
in function links:make/1
called as links:make(2)
This happens before I run the next command which is:
links:test(stop).
After the two commands, I was expecting the following:
Process 2 received stop
Process 1 received stop
Last process now exiting
stop
After some research, I found out that Undef is raised because the function cannot be found when evaluating a function call. Further research on StackOverflow for similar errors did not help. The solutions involved upgrading the installed Erlang version but my problem seems to be a logical one. Being new to Erlang, I cannot point out what it is. As usual, your help will be highly appreciated.