Recently, I began to study the book "Programming Erlang", and I have a question. Is the approach lower to Erlang? This (changed for brevity (no exit message), with deleting the log after a basic check) is a solution to the ring problem from ch4. The outputs of the processes after they transmitted the message the estimated number of times; the first process waits until the last message reaches it and exits.
Besides the general criticism of the style and the being, could you please tell me if there are special 1-2 line functions written like this, the correct style, or if you need to use if-s, case-s, etc.
start_ring( 0, _, _ ) -> {error, badarg}; start_ring( _, 0, _ ) -> {error, badarg}; start_ring( M, N, Message ) -> spawn( ring, run_ring, [M, N, Message, 0] ). % last process that connects the ring run_ring( M, 1, Message, Pid ) when is_pid(Pid) -> loop_ring( M, Message, Pid, false ); % process in the middle run_ring( M, N, Message, Pid ) when is_pid(Pid) -> loop_ring( M, Message, spawn( ring, run_ring, [M, N-1, Message, Pid] ), false ); % first process - special case for one process run_ring( M, 1, Message, _ ) -> loop_ring( M, self() ! Message, self(), true ); % first process run_ring( M, N, Message, _ ) -> NextPid = spawn( ring, run_ring, [M, N-1, Message, self()] ), loop_ring( M, NextPid ! Message, NextPid, true ). loop_ring( 0, _, _, _ ) -> ok; loop_ring( 1, Message, Next, true ) -> ok; loop_ring( M, Message, Next, IsMaster ) -> receive Message -> loop_ring( M - 1, Next ! Message, Next, IsMaster ) end.