# Function BUTLAST, NBUTLAST

### Syntax

• butlast list `&optional` nresult-list
• nbutlast list `&optional` nresult-list

### Description

butlast returns a copy of list from which the last n conses have been omitted. If n is not supplied, its value is 1. If there are fewer than n conses in list, nil is returned and, in the case of nbutlast, list is not modified.

nbutlast is like butlast, but nbutlast may modify list. It changes the cdr of the cons n+1 from the end of the list to nil.

### Examples

```
(defparameter *list* '(1 2 3 4 5 6 7 8 9))

→
*LIST*

(butlast *list*)

→
(1 2 3 4 5 6 7 8)

(butlast *list* 5)

→
(1 2 3 4)

(butlast *list* (+ 5 5))

→
NIL

*list*

→
(1 2 3 4 5 6 7 8 9)

(nbutlast *list* 3)

→
(1 2 3 4 5 6)

*list*

→
(1 2 3 4 5 6)

(nbutlast *list* 99)

→
NIL

*list*

→
(1 2 3 4 5 6)

(butlast '(a b c d))

→
(A B C)

(butlast '((a b) (c d)))

→
((A B))

(butlast '(a))

→
NIL

(butlast nil)

→
NIL

(defparameter *foo* (list 'a 'b 'c 'd))

→
*FOO*

(nbutlast *foo*)

→
(A B C)

*foo*

→
(A B C)

(nbutlast (list 'a))

→
NIL

(nbutlast '())

→
NIL

```

None.

### Exceptional Situations

Should signal an error of type type-error if list is not a proper list or a circular list.

Should signal an error of type type-error if n is not a non-negative integer.

None.

### Example Implementation

To be done.

```
(butlast list n) ≡ (ldiff list (last list n))

```

### Notes

None.

\issue{BUTLAST-NEGATIVE:SHOULD-SIGNAL} \issue{DOTTED-LIST-ARGUMENTS:CLARIFY}