• P16 (**) Drop every N'th element from a list.

    From B. Pym@21:1/5 to All on Mon Sep 2 07:10:35 2024
    Example:
    * (drop '(a b c d e f g h i k) 3)

    Where is "j"?

    (A B D E G H K)
    "

    (defun drop (list n)
    (loop
    :for elt :in list
    :for i :from 1
    :for die-elt-die! = (zerop (mod i n))
    :unless die-elt-die!
    :collect elt))

    Gauche Scheme

    (use srfi-1) ;; circular-list

    (define (dropnth xs n)
    (filter-map
    (lambda (x b) (and b x))
    xs
    (cdr (apply circular-list #f (make-list (- n 1) #t)))))

    (dropnth '(a b c d e f g h i j k l m) 3)
    ===>
    (a b d e g h j k m)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)