(nth integer list)


Determine the nth item in the list.


Like car and cdr, the function nth is used to separate an element from a list. This function is much easier to use in long lists to isolate a single element.

The argument integer represents the number of the item to isolate. Remember that the first item in the list is numbered 0, so that when you want the third item you use 2. When integer is larger than the number of items (actually, number - 1 items) in the list, the nth function returns nil.

Examples

Code Returns
(setq b '(1 2 3 4 5 4 3 2 1)) (1 2 3 4 5 4 3 2 1)
(nth 4 b) 5
(setq c '("one" "two" "three" "four")) (one two three four)
(nth 2 c) three
(nth 5 c) nil

Tell me about...

(last list)

(length list)

(reverse list)

(setq symbol1 statement1 [symbol2 statement2] ...)

LISP Compatibility

Programming Overview of LISP (LISt Processing) Language