select/3 for lists?

From: Ulrich Scholz <>
Date: Wed 22 Jan 2003 03:46:52 PM GMT
Message-ID: <>
Hi everybody,

I'm looking for a library function to get the n-th element of a list.  The
documentation for ord_set mentions a function select/3, whose name suggests
this functionality.  The only select/3 functions in the index are in libraries
iostream and m_map, which are clearly not related to lists.  Maybe, there is a
"hidden" select/3?


If there's no such library function, I'd suggest something like

get_nth_element(List, 1, Elem) :- !,
   List = [Elem|_].	      

get_nth_element(List, N, Elem) :-
   N >= 1,
   N2 is N-1, !, 
   List = [_|List2],
   get_nth_element(List2, N2, Elem).

Ulrich Scholz
Received on Wed Jan 22 18:27:44 2003

This archive was generated by hypermail 2.1.8 : Wed 16 Nov 2005 06:07:21 PM GMT GMT