Discussion:
Detele repeated in a list
(too old to reply)
B. Pym
2024-07-21 00:02:23 UTC
Permalink
(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))
B. Pym
2024-07-21 00:21:28 UTC
Permalink
Post by B. Pym
(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)
HenHanna
2024-07-22 02:56:39 UTC
Permalink
Post by B. Pym
Post by B. Pym
(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))
((8 7) 4 3 2 0)
Gauche doesn't have RemDup built in?
HenHanna
2024-07-22 05:14:26 UTC
Permalink
Post by B. Pym
Post by B. Pym
(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))
((8 7) 4 3 2 0)
Gauche doesn't have RemDup  built in?
i remember that ... Rember was one of the 1st
exercises in intro to Lisp

Maybe there was a naming convention that suggested
that ... Delete is destructive and Remove is not.


_________________________________________________________

delete x list :optional elt= [Function]
delete! x list :optional elt= [Function]

[R7RS list] Equivalent to
(remove (lambda (y) (elt= x y)) list)
(remove! (lambda (y) (elt= x y)) list)

The comparison procedure, elt=, defaults to equal?.


delete-duplicates list :optional elt= [Function]
B. Pym
2024-08-15 01:06:02 UTC
Permalink
Post by B. Pym
Post by B. Pym
(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))
((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))

Loading...