Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "B. Pym" Newsgroups: comp.lang.lisp Subject: P16 (**) Drop every N'th element from a list. Date: Mon, 2 Sep 2024 07:10:35 -0000 (UTC) Organization: A noiseless patient Spider Lines: 29 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Injection-Date: Mon, 02 Sep 2024 09:10:36 +0200 (CEST) Injection-Info: dont-email.me; posting-host="21169b4eafbc5b66ac48973ad23d07f7"; logging-data="1990515"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+rIFctezs0u+mPSZCrOEkt" User-Agent: XanaNews/1.18.1.6 Cancel-Lock: sha1:ix2B8ikPd8L/CRBN7cB3pKxKiOw= Bytes: 1385 > 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)