select/3 for lists?

From: Ulrich Scholz <scholz_at_inferenzsysteme.informatik.tu-darmstadt.de>
Date: Wed 22 Jan 2003 03:46:52 PM GMT
Message-ID: <20030122154652.GA22938@kiwi.intellektik.informatik.tu-darmstadt.de>
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?

Uli


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

scholz@informatik.tu-darmstadt.de
http://www.intellektik.informatik.tu-darmstadt.de/~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