[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: CC mode loads CL
From: |
Luc Teirlinck |
Subject: |
Re: CC mode loads CL |
Date: |
Sun, 18 Jan 2004 19:17:34 -0600 (CST) |
Richard Stallman wrote:
We could add a function delete-duplicates that takes just one argument
and uses equal to compare. Loading cl would extend this, just as
it extends dolist and dotimes.
Or we could call it delete-repeats.
What about the following patches to subr.el and mm-util.el?
Essentially, they contain no new code. I just relocated
`mm-delete-duplicates', renamed it and gave it a new docstring. In as
far as the name is concerned, we can not use `delete-duplicates',
because it uses different defaults (see below). I personally prefer
`delete-repeats', but since two people have already said that they
prefer `delete-dups', I have used that name in my patches.
If desired, I could commit the two patches and write entries for the
NEWS and the Elisp manual.
(delete-dups list) would essentially be equivalent to:
(delete-duplicates list :test 'equal :from-end t) where LIST has to
be a list. The normal CL defaults are 'eql for :test and nil for
:from-end.
The differences are:
1. LIST must be a list, whereas the cl version allows any sequence. All
uses I know of use lists.
2. Uses 'equal to compare instead of 'eql. All uses I am aware of use
'equal.
3. The new (actually "renamed") function keeps the first element in a
set of equal elements, the cl version keeps, by default the last.
In all examples I know of, the order does not matter _anyway_, but
if it would, then systematically keeping the _first_ element seems
to come closer to the intuitive idea of removing duplicates while
keeping the original order and would appear likely to be the wanted
behavior in the majority of cases.
Diffs:
===File ~/subr-diff=========================================
*** subr.el.~1.376.~ Thu Jan 15 18:54:50 2004
--- subr.el Sun Jan 18 17:57:12 2004
***************
*** 209,214 ****
--- 209,227 ----
(if (> n 0) (setcdr (nthcdr (- (1- m) n) x) nil))
x))))
+ (defun delete-dups (list)
+ "Destructively return LIST, with `equal' duplicates removed.
+ LIST must be a proper list. The value of LIST after a call to
+ this function is undefined. Use \(setq LIST (delete-dups LIST))
+ if you want to store the return value in LIST. Of several
+ `equal' occurrences of an element in LIST, the first one is kept."
+ (let (result head)
+ (while list
+ (setq head (car list))
+ (setq list (delete head list))
+ (push head result))
+ (nreverse result)))
+
(defun number-sequence (from &optional to inc)
"Return a sequence of numbers from FROM to TO (both inclusive) as a list.
INC is the increment used between numbers in the sequence and defaults to 1.
============================================================
===File ~/mm-util-diff======================================
*** mm-util.el.~1.29.~ Sat Jan 17 21:04:12 2004
--- mm-util.el Sun Jan 18 17:18:36 2004
***************
*** 453,466 ****
;; This is for XEmacs.
(mm-mule-charset-to-mime-charset charset)))
! (defun mm-delete-duplicates (list)
! "Simple substitute for CL `delete-duplicates', testing with `equal'."
! (let (result head)
! (while list
! (setq head (car list))
! (setq list (delete head list))
! (setq result (cons head result)))
! (nreverse result)))
;; It's not clear whether this is supposed to mean the global or local
;; setting. I think it's used inconsistently. -- fx
--- 453,459 ----
;; This is for XEmacs.
(mm-mule-charset-to-mime-charset charset)))
! (defalias 'mm-delete-duplicates 'delete-dups)
;; It's not clear whether this is supposed to mean the global or local
;; setting. I think it's used inconsistently. -- fx
============================================================
- Re: CC mode loads CL, (continued)
- Re: CC mode loads CL, Luc Teirlinck, 2004/01/15
- Re: CC mode loads CL, Miles Bader, 2004/01/15
- Re: CC mode loads CL, Martin Stjernholm, 2004/01/17
- Re: CC mode loads CL, Miles Bader, 2004/01/17
- Re: CC mode loads CL, Richard Stallman, 2004/01/17
- Re: CC mode loads CL, Luc Teirlinck, 2004/01/17
- Re: CC mode loads CL, Eli Zaretskii, 2004/01/18
- Re: CC mode loads CL, Richard Stallman, 2004/01/18
- Re: CC mode loads CL, Martin Stjernholm, 2004/01/18
- Re: CC mode loads CL, Richard Stallman, 2004/01/19
- Re: CC mode loads CL,
Luc Teirlinck <=
- Re: CC mode loads CL, Luc Teirlinck, 2004/01/18
- Re: CC mode loads CL, Richard Stallman, 2004/01/19
- Re: CC mode loads CL, Luc Teirlinck, 2004/01/19
- Re: CC mode loads CL, Dave Love, 2004/01/16
- Re: CC mode loads CL, Richard Stallman, 2004/01/12
- Re: CC mode loads CL, Dave Love, 2004/01/15
Re: CC mode loads CL, Luc Teirlinck, 2004/01/06
Re: CC mode loads CL, Martin Stjernholm, 2004/01/15