All but a final segment of a list
(implies (and (integerp n) (<= 0 n) (true-listp l)) (equal (length (butlast l n)) (if (< n (length l)) (- (length l) n) 0))) (equal (len (butlast l n)) (nfix (- (len l) (nfix n)))))
For related functions, see take and see nthcdr.
The guard for
Function:
(defun butlast (lst n) (declare (xargs :guard (and (true-listp lst) (integerp n) (<= 0 n)))) (let ((lng (len lst)) (n (nfix n))) (if (<= lng n) nil (take (- lng n) lst))))