aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKenichi Handa2000-12-28 12:15:44 +0000
committerKenichi Handa2000-12-28 12:15:44 +0000
commit1c1c65de36652e5ea0dcec9f7b37d0dc7eeb035c (patch)
tree688c76c8c07ca4e54f51a610ae52678b970bd4c6
parenta816f1c545b1760064ace7c63df551d502de37d8 (diff)
downloademacs-1c1c65de36652e5ea0dcec9f7b37d0dc7eeb035c.tar.gz
emacs-1c1c65de36652e5ea0dcec9f7b37d0dc7eeb035c.zip
(butlast, nbutlast): Moved from cl.el to here.
-rw-r--r--lisp/subr.el14
1 files changed, 14 insertions, 0 deletions
diff --git a/lisp/subr.el b/lisp/subr.el
index e2897481164..2dc159a3424 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -135,6 +135,20 @@ If N is bigger than the length of X, return X."
135 (setq x (cdr x))) 135 (setq x (cdr x)))
136 x)) 136 x))
137 137
138(defun butlast (x &optional n)
139 "Returns a copy of LIST with the last N elements removed."
140 (if (and n (<= n 0)) x
141 (nbutlast (copy-sequence x) n)))
142
143(defun nbutlast (x &optional n)
144 "Modifies LIST to remove the last N elements."
145 (let ((m (length x)))
146 (or n (setq n 1))
147 (and (< n m)
148 (progn
149 (if (> n 0) (setcdr (nthcdr (- (1- m) n) x) nil))
150 x))))
151
138(defun remove (elt seq) 152(defun remove (elt seq)
139 "Return a copy of SEQ with all occurences of ELT removed. 153 "Return a copy of SEQ with all occurences of ELT removed.
140SEQ must be a list, vector, or string. The comparison is done with `equal'." 154SEQ must be a list, vector, or string. The comparison is done with `equal'."