August 19, 2024
P16 - Drop every N'th element from a list
Example:* (drop '(a b c d e f g h i k) 3)(A B D E G H K)
lisp
(defun drop (lista n)
"Drops every N'th element of a list"
(dropaux lista n 1)
)
(defun dropaux (lista n pos)
"Drops every N'th element of a list, but looking now at element POS"
(cond ((eql lista nil) nil)
((= (mod pos n) 0) (dropaux (cdr lista) n 1))
(t (cons (car lista) (dropaux (cdr lista) n (mod (1+ pos) n))))
)
)