Playing with Erlang, I have a loop loop function:
process_loop(...A long list of parameters here...) ->
receive
...Message processing logic involving the function parameters...
end,
process_loop(...Same long list of parameters...)
end.
It looks pretty ugly, so I tried this refactoring:
process_loop(...A long list of parameters...) ->
Loop = fun() ->
receive
...Message processing logic...
end,
Loop()
end,
Loop()
end.
But this turned out to be wrong, since the Loop variable is not connected inside the Loop function. So, I developed a workaround:
process_loop(...A long list of parameters...) ->
Loop = fun(Next) ->
receive
...Message processing logic...
end,
Next(Next)
end,
Loop(Loop)
end.
I have two questions:
Is there any way to implement the idea of โโfragment # 2, but without such โsubsequent (subsequent)โ workarounds?
Do fragments No. 1 and No. 3 differ in terms of performance, or are they equivalent?
source
share