Table of Contents

This function is derived from the Common Lisp NthCDR function.

The recursive version is shown, though not recommended for long lists. AutoLisp has a limitation on recursive calls and might fail at or around the 20,000th item in the list.


Recursive version

(defun nthcdr (n l /)
  (if (> n 0) (nthcdr (1- n) (cdr l)) l))

Iterative version

(defun nthcdr (n l /)
  (repeat n (setq l (cdr l))))

An optimized [1] version for long lists and/or large quantities of CDR's

(defun nthcdr (n l /)
  (repeat (/ n 4) (setq l (cddddr l)))
  (repeat (rem n 4) (setq l (cdr l)))
1. Derived from code posted by Elpanov Evgeniy here: http://www.theswamp.org/index.php?topic=32428.msg380205#msg380205