Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

BOFH excuse #318: Your EMAIL is now being delivered by the USPS.


comp / comp.lang.lisp / P16 (**) Drop every N'th element from a list.

SubjectAuthor
o P16 (**) Drop every N'th element from a list.B. Pym

1
Subject: P16 (**) Drop every N'th element from a list.
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Mon, 2 Sep 2024 07:10 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Nobody447095@here-nor-there.org (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: <vb3od7$1snrj$1@dont-email.me>
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=
View all headers

> 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)

1

rocksolid light 0.9.8
clearnet tor