Micheus is right, the binary comprehension is the best for this code.
So example is kind of bad, for the question.
And the answer is that it depends, you will have to measure which one is fastest,
in current release, previously example 3 was always best and will be always be
if you don't need the lists:reverse at the end.
Now (since Björn have made some optimizations in erlang) if you really want
the fastest implementation you will have to measure, but for most of the
cases it doesn't matter if you use 1) or 3)
Number 2 is ugly and creates an unnecessary extra list.
If you want to return more than one thing only 3) is possible.
What I think Joe is saying is to avoid doing something like this.
init() ->
Result = loop(),
{ok, Result}.
loop() ->
receive
quit -> 42;
Msg -> io:format("Msg ~p~n",[Msg]),
loop()
end.
Which must save init function on the stack until loop returns.
See: http://en.wikipedia.org/wiki/Tail_call for a better explanation :-)
So example is kind of bad, for the question.
And the answer is that it depends, you will have to measure which one is fastest,
in current release, previously example 3 was always best and will be always be
if you don't need the lists:reverse at the end.
Now (since Björn have made some optimizations in erlang) if you really want
the fastest implementation you will have to measure, but for most of the
cases it doesn't matter if you use 1) or 3)
Number 2 is ugly and creates an unnecessary extra list.
If you want to return more than one thing only 3) is possible.
What I think Joe is saying is to avoid doing something like this.
init() ->
Result = loop(),
{ok, Result}.
loop() ->
receive
quit -> 42;
Msg -> io:format("Msg ~p~n",[Msg]),
loop()
end.
Which must save init function on the stack until loop returns.
See: http://en.wikipedia.org/wiki/Tail_call for a better explanation :-)