; nth item in a linked list

(define (nth n xs)
  (if (null? xs)
      (error 'nth "out of range")
      (if (zero? n) (car xs)
          (nth (- n 1) (cdr xs)))))

(display (nth 0 '(0 1 2 3 4))) (newline)
(display (nth 1 '(0 1 2 3 4))) (newline)
(display (nth 2 '(0 1 2 3 4))) (newline)
(display (nth 3 '(0 1 2 3 4))) (newline)
(display (nth 4 '(0 1 2 3 4))) (newline)