A slightly more general function:
(defun remove-by-position (pred lst) (labels ((walk-list (pred lst idx) (if (null lst) lst (if (funcall pred idx) (walk-list pred (cdr lst) (1+ idx)) (cons (car lst) (walk-list pred (cdr lst) (1+ idx))))))) (walk-list pred lst 1)))
What we use to implement the desired nth removal:
(defun remove-nth (n list) (remove-by-position (lambda (i) (= in)) list))
And the call:
(remove-nth 4 '(1 2 3 2 4 6))
Edit: Applied comments from Samuel's comment.
source share