next up previous
Contents Next: nthcdr (FUNCTION) Up: Appendix: Selected LISP Previous: not (PREDICATE)

nth (FUNCTION)

Format: (nth <index> <list>)

Required arguments: 2

<index>: any expression which returns a positive integer (fixnum). <list>: any expression which returns a list.

The function nth returns the indexed element of <list>. <index> must be a non-negative integer. 0 indicates the first element of <list>, 1 the second, etc. An index past the end of the list will cause nth to return nil.

Examples:

>(nth 0 '(picard riker work crusher))
PICARD

>(nth 2 '((captain picard) 
          (commander riker) 
          (lieutenant worf)  
          (ensign crusher)))
(LIEUTENANT WORF)



© Colin Allen & Maneesh Dhagat
November 1999