[erlang-questions] Erlang way for process-as-library?

Mats Cronqvist <>
Thu Feb 8 11:13:11 CET 2007


Torbjorn Tornkvist wrote:
> I'm surprised over the long thread my rough sketch caused.

   blame robert...

> In real life I would of course do almost as in Mats proposal,
> with some minor changes... :-)

   but of course :>
   i think your version is objectively better. i just dislike the verbosity of the
fun() -> init(Self) end
   syntax.

> init(Daddy) ->
>   try register(name,self()), Daddy ! {ok,self(),self()}
>   catch error:badarg -> Daddy ! {ok,self(),whereis(name)},exit(normal)
>   end,
>   loop().

   to be REALLY correct this should recurse if the whereis fails (which can 
happen if there is a process 'name' that exits between the calls to register and 
whereis).

   mats



More information about the erlang-questions mailing list