• Re: Detele repeated in a list

    From B. Pym@21:1/5 to Pascal Costanza on Sun Jul 21 00:02:23 2024
    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))

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From B. Pym@21:1/5 to B. Pym on Sun Jul 21 00:21:28 2024
    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)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From HenHanna@21:1/5 to B. Pym on Sun Jul 21 19:56:39 2024
    On 7/20/2024 5:21 PM, 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)



    Gauche doesn't have RemDup built in?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From HenHanna@21:1/5 to HenHanna on Sun Jul 21 22:14:26 2024
    On 7/21/2024 7:56 PM, HenHanna wrote:
    On 7/20/2024 5:21 PM, 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)



    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]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From B. Pym@21:1/5 to B. Pym on Thu Aug 15 01:06:02 2024
    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))

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)