Copyright (C) 2000-2012 |
GNU Info (librep.info)Accessing List ElementsAccessing List Elements ....................... The most flexible method of accessing an element in a list is via a combination of the `car' and `cdr' functions. There are other functions which provide an easier way to get at the elements in a flat list. These will usually be faster than a string of `car' and `cdr' operations. - Function: nth count list This function returns the element COUNT elements down the list, therefore to access the first element use a COUNT of zero (or even better the `car' function). If there are too few elements in the list and no element number COUNT can be found `()' is returned. (nth 3 '(0 1 2 3 4 5)) => 3 (nth 0 '(foo bar) => foo - Function: nthcdr count list This function takes the cdr of the list LIST COUNT times, returning the last cdr taken. (nthcdr 3 '(0 1 2 3 4 5)) => (3 4 5) (nthcdr 0 '(foo bar)) => (foo bar) - Function: last list This function returns the last element in the list LIST. If the list has zero elements `()' is returned. (last '(1 2 3)) => 3 (last '()) => () - Function: member object list This function scans through the list LIST until it finds an element which is `equal' to OBJECT. The tail of the list (the cons cell whose car is the matched object) is then returned. If no elements match OBJECT then the empty list `()' is returned. (member 'c '(a b c d e)) => (c d e) (member 20 '(1 2)) => () - Function: memq object list This function is similar to `member' except that comparisons are performed by the `eq' function not `equal'. automatically generated by info2www version 1.2.2.9 |