[erlang-questions] list_element()
Ivan Uemlianin
ivan@REDACTED
Thu May 27 16:40:57 CEST 2010
Dear Henning
Do you mean you need to access the nth element of a list? Is
lists:nth/2 no good?
http://www.erlang.org/doc/man/lists.html#nth-2
Best wishes
Ivan
On 27/05/2010 15:31, Henning Diedrich wrote:
> Hi list,
>
> I need to access a list element by index.
>
> I wrote a function but it looks most clumsy.
>
> I am looking for maximal performance. Should I instead convert the
> list to a tuple and use element()?
>
> The lists are ~ 10 to 30 elements in length. (<-- not an attempt to
> define a frame).
>
> For curiosity, does the below tail-recurse correctly?
>
> listOrd(_, []) -> nil;
>
> listOrd(Searched, List) when is_list(List) ->
>
> listOrd(Searched, List, 1).
>
> listOrd(_, [], _) -> nil;
>
> listOrd(Searched, [ Element | Tail ], Count) ->
>
> case Searched == Element of
> true -> Count;
> _ -> listOrd(Searched, Tail, Count + 1)
> end.
>
>
>
> Thanks for your time,
> Henning
>
--
============================================================
Ivan A. Uemlianin
Speech Technology Research and Development
ivan@REDACTED
www.llaisdy.com
llaisdy.wordpress.com
www.linkedin.com/in/ivanuemlianin
"Froh, froh! Wie seine Sonnen, seine Sonnen fliegen"
(Schiller, Beethoven)
============================================================
More information about the erlang-questions
mailing list