• P08 (**) Eliminate consecutive duplicates of list elements.

    From B. Pym@Nobody447095@here-nor-there.org to comp.lang.lisp,comp.lang.scheme on Mon Jul 21 13:17:50 2025
    From Newsgroup: comp.lang.scheme


    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 and basically fall down frothing at the mouth if they see [heterodoxy].
    --- Kenny Tilton
    The good news is, it's not Lisp that sucks, but Common Lisp. --- Paul Graham --- Synchronet 3.21a-Linux NewsLink 1.2