- (let*
- ((head x)
- (trailing x))
-
- ;; find n in...
- (do ((i 0 (1+ i)))
- ((or ( >= i (1- n))
- (not head)
- (not (consp (cdr head)))))
- (setf head (cdr head)))
-
- (when (consp (cdr head))
-
- (setf trailing x)
- (setf head (cdr head))
-
- ;; walk until the end
- (do ()
- ((or
- (not (consp head))
- (not (cdr head))))
-
- (setf head (cdr head))
- (setf trailing (cdr trailing)))
-
- ;; snip
- (rplacd trailing nil)
-
- x)))))
+ (let* ((head x)
+ (trailing (nthcdr n x)))
+ ;; If there are enough conses
+ (when (consp trailing)
+ (while (consp (cdr trailing))
+ (setq head (cdr head))
+ (setq trailing (cdr trailing)))
+ ;; snip
+ (rplacd head nil)
+ x)))))