Silly Qn': Process exits at spawn

Vladimir Sekissov svg@REDACTED
Mon Oct 13 18:44:33 CEST 2003


Good day,

You have yet another error at lists:append/2 in registry_loop/1.
This code would work only if  

add_neuron (Name) ->
     neural_registry ! {self(), add, [Name]}.

rewrite as

...
registry_loop ([Name|Val]);
...

and do lists:reverse(Val) in registered_neurons/0

or

...
registry_loop (lists:append(Val,[Name]));
...

lists:append(List1, List2) is also equivalent for

List1 ++ List2

Best Regards,
Vladimir Sekissov

chris.danx> -module(neural).
chris.danx> -export([create_registry/0,
chris.danx> 	 stop_registry/0,
chris.danx> 	 registry_loop/1,
chris.danx> 	 add_neuron/1,
chris.danx> 	 registered_neurons/0]).
chris.danx> 
chris.danx> create_registry () ->
chris.danx>      Pid = spawn (neural, registry_loop, []),
chris.danx>      register (neural_registry, Pid).
chris.danx> 
chris.danx> 
chris.danx> stop_registry () ->
chris.danx>      neural_registry ! stop.
chris.danx> 
chris.danx> 
chris.danx> add_neuron (Name) ->
chris.danx>      neural_registry ! {self(), add, Name}.
chris.danx> 
chris.danx> 
chris.danx> registered_neurons () ->
chris.danx>      neural_registry ! {self(), reg_neurons},
chris.danx>      receive
chris.danx> 	{Registry, Vals} ->
chris.danx> 	    Vals
chris.danx>      end.
chris.danx> 
chris.danx> registry_loop(Val) ->
chris.danx>      receive
chris.danx> 	{From, add, Name} ->
chris.danx> 	    registry_loop (lists:append (Val, Name));
chris.danx> 	stop ->
chris.danx> 	    true;
chris.danx> 	Other ->
chris.danx> 	    registry_loop (Val)
chris.danx>      end.
chris.danx> 	
chris.danx> 
chris.danx> Thanks,
chris.danx> Chris
chris.danx> 



More information about the erlang-questions mailing list