Skip to content

Commit e5f472b

Browse files
committed
add &optional n in last
1 parent 3e25e57 commit e5f472b

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lisp/l/common.l

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,9 +448,10 @@ if pos is bigger than the length of list, item is nconc'ed at the tail"
448448
(nconc result1 result2)))
449449

450450
(defun rotate-list (l) (append (cdr l) (list (car l))))
451-
(defun last (x)
452-
(while (consp (cdr x)) (setq x (cdr x)))
453-
x)
451+
(defun last (x &optional (n 1))
452+
(unless (integerp n)
453+
(error "last &optional n must be integer"))
454+
(nthcdr (max (- (length x) n) 0) x))
454455
(defun copy-tree (x) (subst t t x))
455456
(defun copy-list (x) (nreverse (reverse x)))
456457
(defun nreconc (x y) (nconc (nreverse x) y))

0 commit comments

Comments
 (0)