Deutsch   English   Français   Italiano  
<v9jk9o$lrgv$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: "B. Pym" <Nobody447095@here-nor-there.org>
Newsgroups: comp.lang.lisp
Subject: Re: Detele repeated in a list
Date: Thu, 15 Aug 2024 01:06:02 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <v9jk9o$lrgv$1@dont-email.me>
References: <v7hj6b$3ooop$1@dont-email.me> <v7hka3$3oudp$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Thu, 15 Aug 2024 03:06:03 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="7e5ecf5f7253603983f636ec904f7241";
	logging-data="716319"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/4LkR23JnqkakcsuylTum1"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:0RzvAKgAShj4Scm/3L1apwdpSko=
Bytes: 1713

B. Pym wrote:

> B. Pym wrote:
> 
> > Pascal Costanza wrote:
> > 
> > > (defun rem-duplicates (list)
> > >    (loop for (first . rest) on (append list list)
> > >          unless (member first (reverse rest) :test #'equal)
> > >          collect first))
> > 
> > Gauche Scheme
> > 
> > (define (rem-dups lst)
> >   (fold
> >     (lambda (x accum) (if (member x accum) accum (cons x accum)))
> >     '()
> >     lst))
> > 
> > (rem-dups '(0 2 3 4 (8 7) 3 2 0 (8 7)))
> >   ===>
> > (4 3 2 0 (8 7))
> 
> Actual result:
> 
> ((8 7) 4 3 2 0)


newLISP

(define (rem-dups lst)
  ;; Using "apply" for "reduce" or "fold".
  (apply
    (fn (accum x) (if (member x accum) accum (push x accum -1)))
    (cons '() lst)
    2))

(rem-dups '(0 2 3 4 (8 7) 3 2 0 (8 7)))

(0 2 3 4 (8 7))