[erlang-questions] Swap 2 elements within a list a la Erlang ?
Jani Hakala
jahakala@REDACTED
Sun Jun 10 11:44:25 CEST 2007
Andreas Bakurov <andreasmk2@REDACTED> writes:
> It works but it seems ugly to me and not in a spirit of functional
> programming , furthermore it is slow for lists of 10000 elements and more.
> Is there a more elegant way to write this function ? If yes, please send
> me an example...
>
I would try using list_to_tuple and then element and setelement to
update the tuple (you get a new tuple when using setelement). Then
after the swapping tuple_to_list.
This should be a faster than updating a list if erlang/beam is smart
when updating a tuple...
Jani Hakala
More information about the erlang-questions
mailing list