emacs-pretest-bug
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CC mode loads CL


From: Karl Heuer
Subject: Re: CC mode loads CL
Date: Tue, 10 Feb 2004 21:31:33 -0500

Dave Love <address@hidden> writes:
>Luc Teirlinck <address@hidden> writes:
>> I installed the non-consing version of `delete-dups' and added an item
>> to the NEWS.
>
>[That seems a rather unfortunate name/implementation to me.]

I'll withhold opinion on the name, but as for the implementation...

In keeping with the earlier suggestion that it's better to keep
the first of any duplicated elements rather than the last, I
propose the following implementation, which satisfies that
requirement and is also simpler.  (Note that since the first
element of the list is always a "keeper", the modified list is
always the same as the return value, and it's no longer strictly
necessary for the caller to wrap this in a setq.)

(defun delete-dups (list)
    "Destructively return LIST, with `equal' duplicates removed.
LIST must be a proper list.  Of several `equal' occurrences of an
element in LIST, the first one is kept."
  (let ((tail list))
    (while tail
      (setcdr tail (delete (car tail) (cdr tail)))
      (setq tail (cdr tail))))
  list)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]