[erlang-questions] list:join() for erlang?
Tim Bates
tim@REDACTED
Sat Sep 15 06:23:36 CEST 2007
Paulo Sérgio Almeida wrote:
> Regarding list reverse, while playing around and observing:
>
> 85> erlang:is_builtin(lists, reverse, 1).
> false
>
> I found out that what is builtin is another function, reverse/2, which
> is not much advertised, but that may be very useful, as the fastest way
> to simultaneously reverse a list and concatenate to another.
From lists.erl, reverse/1 calls reverse/2 to do the actual reversing,
except in a couple of special cases (where length(L) < 3).
reverse([] = L) ->
L;
reverse([_] = L) ->
L;
reverse([A, B]) ->
[B, A];
reverse([A, B | L]) ->
lists:reverse(L, [B, A]).
Tim.
--
Tim Bates
tim@REDACTED
More information about the erlang-questions
mailing list