I am a working on a school project in Erlang. I am trying to make a master process here which will spawn the 5 processes and then these process will make a call to the people in the list. The text file is as follows :
{john, [Jill,Joe,bob]}. {Jill, [bob,Joe,bob]}. {sue, [jill,jill,jill,bob,jill]}. {bob, [john]}. {joe, [sue]}.
but I couldnot create new processes as I'm receiving this error. Please help me solve this, I don't understand the error.
invoke(Elem) ->
{X,Y} = Elem,
Pid = spawn(calling, people, [X,Y]),
register(X,Pid).
second module
people(N,Persons) ->
lists:foreach(fun contact/1, Persons),
io:fwrite("in people\n").
The error I'm getting is:
=ERROR REPORT==== 18-Jun-2020::20:27:49 ===
Error in process <0.59.0> with exit value:
{undef,[{calling,people,[john,[jill,joe,bob]],[]}]}
=ERROR REPORT==== 18-Jun-2020::20:27:49 ===
Error in process <0.60.0> with exit value:
{undef,[{calling,people,[jill,[bob,joe,bob]],[]}]}
=ERROR REPORT==== 18-Jun-2020::20:27:49 ===
Error in process <0.61.0> with exit value:
{undef,[{calling,people,[sue,[jill,jill,jill,bob,jill]],[]}]}
=ERROR REPORT==== 18-Jun-2020::20:27:49 ===
Error in process <0.62.0> with exit value:
{undef,[{calling,people,[bob,[john]],[]}]}
=ERROR REPORT==== 18-Jun-2020::20:27:49 ===
Error in process <0.63.0> with exit value:
{undef,[{calling,people,[joe,[sue]],[]}]}
1条答案
按热度按时间bakd9h0s1#
The error message says that the function
people
with 2 arguments does not exist in the modulecalling
. There are several possibilities for this:calling
does not existcalling
is not reachable (not in the path)calling
is not compiledpeople/2
is not exported in the modulecalling
Edit
You can check the path code (the list of places where the Erlang machine will search for modules) with the command
rp(code:get_path()).
. If you did nothing special, you will get a list containing"."
as first element and then all the erlang libraries. The dot means the working directory.With the command
pwd().
, you can get the place of this working directory.Then you should look for a file named calling.beam. If it does not exist, you must compile the module for example with the command
c(calling).
in the shell.If it exists but is in an another place than the working directory, you have to choose between one of these solutions (I can't know which one is better in your case):
code:add_path("Path/to/your/beam/file")
cwd("beam/file/directory").
.In Erlang, although it is not mandatory, people use to organize their files in the same way, it looks like:
This is enough for starting and make some simple programs. For real application, people use tools like rebar3 to manage and organize the files and the build process.