Sujet : P08 (**) Eliminate consecutive duplicates of list elements.
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lisp comp.lang.schemeDate : 21. Jul 2025, 14:17:50
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <105lelr$3vhdm$1@dont-email.me>
User-Agent : XanaNews/1.18.1.6
If a list contains repeated elements they should be replaced
with a single copy of the element. The order of the elements
should not be changed.
Example:
* (compress '(a a a a b c c a a d e e e e))
(A B C A D E)
Gauche Scheme
Assuming that the list doesn't contain #f.
(define (del-dups seq)
(fold-right*
(lambda (e f accum) (if (equal? e f) accum (cons e accum)))
'()
seq))
(del-dups '(a a a a b c c a a d e e e e))
===>
(a b c a d e)
Given:
(define (fold-right* kons knil xs)
(fold-right
(lambda (e accum)
(kons e (if (pair? accum) (car accum) #f) accum))
knil
xs))
-- [T]he problem is that lispniks are as cultish as any other devout group andbasically fall down frothing at the mouth if they see [heterodoxy]. --- Kenny TiltonThe good news is, it's not Lisp that sucks, but Common Lisp. --- Paul Graham
| Date | Sujet | # | | Auteur |
| 21 Jul 25 | P08 (**) Eliminate consecutive duplicates of list elements. | 1 | | B. Pym |
Haut de la page
Les messages affichés proviennent d'usenet.
NewsPortal