Mercurial > emacs
comparison lisp/subr.el @ 110971:80846b446563
lisp/subr.el (last): Use `safe-length' instead of `length' (bug#7206).
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Thu, 14 Oct 2010 01:15:03 +0200 |
parents | 388aaaced495 |
children | dff76f22a051 |
comparison
equal
deleted
inserted
replaced
110970:029adaffe445 | 110971:80846b446563 |
---|---|
288 If LIST is nil, return nil. | 288 If LIST is nil, return nil. |
289 If N is non-nil, return the Nth-to-last link of LIST. | 289 If N is non-nil, return the Nth-to-last link of LIST. |
290 If N is bigger than the length of LIST, return LIST." | 290 If N is bigger than the length of LIST, return LIST." |
291 (if n | 291 (if n |
292 (and (> n 0) | 292 (and (> n 0) |
293 (let ((m (length list))) | 293 (let ((m (safe-length list))) |
294 (if (< n m) (nthcdr (- m n) list) list))) | 294 (if (< n m) (nthcdr (- m n) list) list))) |
295 (and list | 295 (and list |
296 (nthcdr (1- (length list)) list)))) | 296 (nthcdr (1- (safe-length list)) list)))) |
297 | 297 |
298 (defun butlast (list &optional n) | 298 (defun butlast (list &optional n) |
299 "Return a copy of LIST with the last N elements removed." | 299 "Return a copy of LIST with the last N elements removed." |
300 (if (and n (<= n 0)) list | 300 (if (and n (<= n 0)) list |
301 (nbutlast (copy-sequence list) n))) | 301 (nbutlast (copy-sequence list) n))) |