# HG changeset patch # User Kenichi Handa # Date 978005744 0 # Node ID 1486728b21f0c52edf41aa91bf9efaee78f83021 # Parent 09222394e99464a77f63f9b7af5dc7db3b6f82e4 (butlast, nbutlast): Moved from cl.el to here. diff -r 09222394e994 -r 1486728b21f0 lisp/subr.el --- 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'."