[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: should search ring contain duplicates?
From: |
David Kastrup |
Subject: |
Re: should search ring contain duplicates? |
Date: |
Thu, 04 May 2006 12:29:56 +0200 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) |
address@hidden (Kim F. Storm) writes:
> address@hidden (Kim F. Storm) writes:
>
>> I definitely think we need the history-push macro!
>> Here is something which works for me:
>
> .. almost :-) Here is a better version:
>
> (defmacro history-push (newelt history &optional maxelt)
> "Add NEWELT to the history list stored in the symbol HISTORY.
> If symbol MAXELT is specified, the maximum length of the history is
> specified by the value of that symbol. Otherwise, the maximum history
> length is to the value of the `history-length' property on symbol
> HISTORY, if set, or to the value of the `history-length' variable.
> Remove duplicates of NEWELT unless `history-delete-duplicates' is nil."
> (declare (debug (form sexp)))
> (unless maxelt
> (setq maxelt `(or (get ',history 'history-length)
> history-length)))
> `(let ((len ,maxelt))
> (if history-delete-duplicates
> (setq ,history (delete ,newelt ,history)))
> (setq ,history (cons ,newelt ,history))
> (when (integerp len)
> (if (= 0 len)
> (setq ,history nil)
> (if (> (length ,history) len)
> (setcdr (nthcdr (1- len) ,history) nil))))))
What is the rationale for making this a macro? It's not performance
relevant, and not short. Seems like something
(defun history-push (newelt history &optional maxelt)
"Add NEWELT to the history list stored in the symbol HISTORY.
If symbol MAXELT is specified, the maximum length of the history is
specified by the value of that symbol. Otherwise, the maximum history
length is to the value of the `history-length' property on symbol
HISTORY, if set, or to the value of the `history-length' variable.
Remove duplicates of NEWELT unless `history-delete-duplicates' is nil."
(unless maxelt
(setq maxelt (or (get history 'history-length)
history-length)))
(if history-delete-duplicates
(set history (delete newelt (symbol-value history))))
(set history (cons newelt (symbol-value history)))
(when (integerp maxelt)
(if (= 0 maxelt)
(set history nil)
(if (> (length (symbol-value history)) maxelt)
(setcdr (nthcdr (1- maxelt) (symbol-value history)) nil)))))
Sure, you need to quote history in the call then, but it seems like
the trouble for a macro is not really warranted.
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
- should search ring contain duplicates?, Drew Adams, 2006/05/02
- Re: should search ring contain duplicates?, Dan Nicolaescu, 2006/05/03
- Re: should search ring contain duplicates?, Kim F. Storm, 2006/05/03
- Re: should search ring contain duplicates?, Juri Linkov, 2006/05/03
- Re: should search ring contain duplicates?, Kim F. Storm, 2006/05/03
- Re: should search ring contain duplicates?, Kim F. Storm, 2006/05/04
- Re: should search ring contain duplicates?,
David Kastrup <=
- Re: should search ring contain duplicates?, Stefan Monnier, 2006/05/04
- Re: should search ring contain duplicates?, Kim F. Storm, 2006/05/04
- Re: should search ring contain duplicates?, David Kastrup, 2006/05/04
- Re: should search ring contain duplicates?, Richard Stallman, 2006/05/05
- Re: should search ring contain duplicates?, Kim F. Storm, 2006/05/05
- Re: should search ring contain duplicates?, Eli Zaretskii, 2006/05/06
- Re: should search ring contain duplicates?, Richard Stallman, 2006/05/06
- Re: should search ring contain duplicates?, Kim F. Storm, 2006/05/07
- Re: should search ring contain duplicates?, Stuart D. Herring, 2006/05/04
- Re: should search ring contain duplicates?, David Kastrup, 2006/05/04