Mercurial > emacs
changeset 34898:1486728b21f0
(butlast, nbutlast): Moved from cl.el to here.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Thu, 28 Dec 2000 12:15:44 +0000 |
parents | 09222394e994 |
children | 6ab3c587f8bc |
files | lisp/subr.el |
diffstat | 1 files changed, 14 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/lisp/subr.el Thu Dec 28 12:15:20 2000 +0000 +++ b/lisp/subr.el Thu Dec 28 12:15:44 2000 +0000 @@ -135,6 +135,20 @@ (setq x (cdr x))) x)) +(defun butlast (x &optional n) + "Returns a copy of LIST with the last N elements removed." + (if (and n (<= n 0)) x + (nbutlast (copy-sequence x) n))) + +(defun nbutlast (x &optional n) + "Modifies LIST to remove the last N elements." + (let ((m (length x))) + (or n (setq n 1)) + (and (< n m) + (progn + (if (> n 0) (setcdr (nthcdr (- (1- m) n) x) nil)) + x)))) + (defun remove (elt seq) "Return a copy of SEQ with all occurences of ELT removed. SEQ must be a list, vector, or string. The comparison is done with `equal'."