Silly Qn': Process exits at spawn
Mickael Remond
mickael.remond@REDACTED
Mon Oct 13 19:04:27 CEST 2003
* chris.danx <chris.danx@REDACTED> [2003-10-13 17:31:14 +0100]:
> Hi,
>
> What's wrong with this module? I've not played with erlang in ages and
> even then only for a few days. The problem seems to be that the
> registered process exists at spawn or very quickly but I don't
> understand why. Can someone please tell me what is wrong?
>
>
> -module(neural).
> -export([create_registry/0,
> stop_registry/0,
> registry_loop/1,
> add_neuron/1,
> registered_neurons/0]).
>
> create_registry () ->
> Pid = spawn (neural, registry_loop, []),
=> Your calling registry_loop/0 here which does not exist.
> register (neural_registry, Pid).
>
>
> stop_registry () ->
> neural_registry ! stop.
>
>
> add_neuron (Name) ->
> neural_registry ! {self(), add, Name}.
>
>
> registered_neurons () ->
> neural_registry ! {self(), reg_neurons},
> receive
> {Registry, Vals} ->
> Vals
> end.
>
> registry_loop(Val) ->
> receive
> {From, add, Name} ->
> registry_loop (lists:append (Val, Name));
> stop ->
> true;
> Other ->
> registry_loop (Val)
> end.
>
>
> Thanks,
Your are welcome,
--
Mickaël Rémond
http://www.erlang-projects.org/
More information about the erlang-questions
mailing list