&optional
n → taillast returns the last n conses (not the last n elements) of list). If list is nil, last returns nil.
If n is zero, the atom that terminates list is returned. If n is greater than or equal to the number of cons cells in list, the result is list.
(last nil)
→(last '(1 2 3))
→(3)
(last '(1 2 . 3))
→(2 . 3)
(defparameter *x* (list 'a 'b 'c 'd))
→*X*
(last *x*)
→(D)
(rplacd (last *x*) (list 'e 'f))
→(D E F)
*x*
→(A B C D E F)
(last *x*)
→(F)
(last '(a b c))
→(C)
(last '(a b c) 0)
→(last '(a b c) 1)
→(C)
(last '(a b c) 2)
→(B C)
(last '(a b c) 3)
→(A B C)
(last '(a b c) 4)
→(A B C)
(last '(a . b) 0)
→B
(last '(a . b) 1)
→(A . B)
(last '(a . b) 2)
→(A . B)
None.
None.
The consequences are undefined if list is a circular list.
Should signal an error of type type-error if n is not a non-negative integer.
The following code could be used to define last.
(defun last (list &optional (n 1)) (check-type n (integer 0)) (do ((l list (cdr l)) (r list) (i 0 (1+ i))) ((atom l) r) (if (>= i n) (pop r))))
None.
\issue{LAST-N} \issue{DOTTED-LIST-ARGUMENTS:CLARIFY}