Take the 2-minute tour ×

The following two expressions are equivalent:

(third (list 1 2 3 4))

(first (nthcdr 2 (list 1 2 3 4)))

However, using "third," "fourth," "fifth," etc. isn't always practical and (first (nthcdr n list)) seems a little verbose. Is there a way to say something like (item 2 (list 1 2 3 4)) to get the nth item in a list?

share|improve this question
Have you tried nth? –  Gareth Rees Nov 24 '10 at 13:30

2 Answers 2

up vote 8 down vote accepted
(nth 3 (list 1 2 3 4))

returns 4th item (zero based!)

[Function] nth n list

(nth n list) returns the nth element of list, where the car of the list is the ``zeroth'' element. The argument n must be a non-negative integer. If the length of the list is not greater than n, then the result is (), that is, nil. (This is consistent with the idea that the car and cdr of () are each ().) For example:

(nth 0 '(foo bar gack)) => foo (nth 1 '(foo bar gack)) => bar
(nth 3 '(foo bar gack)) => ()

Compatibility note: This is not the same as the Interlisp function called nth, which is similar to but not exactly the same as the Common Lisp function nthcdr. This definition of nth is compatible with Lisp Machine Lisp and NIL (New Implementation of Lisp). Also, some people have used macros and functions called nth of their own in their old MacLisp programs, which may not work the same way. nth may be used to specify a place to setf; when nth is used in this way, the argument n must be less than the length of the list.

Note that the arguments to nth are reversed from the order used by most other sequence selector functions such as elt.

share|improve this answer

NTH works for lists.

ELT works for sequences. Sequences are lists and all kinds of one-dimensional arrays (vector, string, ...).

This means that ELT is the more general accessor, which not only works with lists, but also with one-dimensional arrays.

share|improve this answer

Your Answer


