User Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

cl:functions:butlast [2019/11/11 05:00]
cl:functions:butlast [2019/11/19 04:00] (current)
Line 1: Line 1:
 +====== Function BUTLAST, NBUTLAST ======
  
 +====Syntax====
 +  * **butlast ** //list ''&​optional''​ n// → //​result-list//​
 +  * **nbutlast** //list ''&​optional''​ n// → //​result-list//​
 +
 +====Arguments and Values====
 +  * //list// - a //​[[CL:​Glossary:​list]]//,​ which might be a //​[[CL:​Glossary:​dotted list]]// but must not be a //​[[CL:​Glossary:​circular list]]//.
 +  * //n// - a non-negative //​[[CL:​Glossary:​integer]]//​.
 +  * //​result-list//​ - a //​[[CL:​Glossary:​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//, **[[CL:​Constant Variable:​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 //​[[CL:​Glossary:​cdr]]//​ of the //​[[CL:​Glossary:​cons]]//​ //n//+1 from the end of the //list// to **[[CL:​Constant Variable:​nil]]**.  ​
 +
 +====Examples====
 +<​blockquote>​
 +([[CL:​Macros:​defparameter]] *list* '(1 2 3 4 5 6 7 8 9)) <​r>​*LIST*</​r>​
 +(butlast *list*) <r>(1 2 3 4 5 6 7 8)</​r>​
 +(butlast *list* 5) <r>(1 2 3 4)</​r>​
 +(butlast *list* (+ 5 5)) <​r>​[[CL:​Constant Variable:​nil|NIL]]</​r>​
 +*list* <r>(1 2 3 4 5 6 7 8 9)</​r>​
 +(nbutlast *list* 3) <r>(1 2 3 4 5 6)</​r>​
 +*list* <r>(1 2 3 4 5 6)</​r>​
 +(nbutlast *list* 99) <​r>​[[CL:​Constant Variable:​nil|NIL]]</​r>​
 +*list* <r>(1 2 3 4 5 6)</​r>​
 +(butlast '(a b c d)) <r>(A B C)</​r>​
 +(butlast '((a b) (c d))) <​r>​((A B))</​r>​
 +(butlast '(a)) <​r>​[[CL:​Constant Variable:​nil|NIL]]</​r>​
 +(butlast [[CL:​Constant Variable:​nil]]) <​r>​[[CL:​Constant Variable:​nil|NIL]]</​r>​
 +([[CL:​Macros:​defparameter]] *foo* ([[CL:​Functions:​list]] 'a 'b 'c 'd)) <​r>​*FOO*</​r>​
 +(nbutlast *foo*) <r>(A B C)</​r>​
 +*foo* <r>(A B C)</​r>​
 +(nbutlast ([[CL:​Functions:​list]] 'a)) <​r>​[[CL:​Constant Variable:​nil|NIL]]</​r>​
 +(nbutlast '()) <​r>​[[CL:​Constant Variable:​nil|NIL]]</​r>​
 +</​blockquote>​
 +
 +====Affected By====
 +None.
 +
 +====Exceptional Situations====
 +Should signal an error of type **[[CL:​Types:​type-error]]** if //list// is not a //​[[CL:​Glossary:​proper list]]// or a //​[[CL:​Glossary:​circular list]]//.
 +
 +Should signal an error of type **[[CL:​Types:​type-error]]** if //n// is not a non-negative //​[[CL:​Glossary:​integer]]//​.
 +
 +====See Also====
 +None.
 +
 +====Example Implementation====
 +To be done.
 +
 +<​blockquote>​
 +(butlast //list// //n//) ≡ ([[CL:​Functions:​ldiff]] //list// ([[CL:​Functions:​last]] //list// //n//))
 +</​blockquote>​
 +
 +====Notes====
 +None.
 +
 +\issue{BUTLAST-NEGATIVE:​SHOULD-SIGNAL}
 +\issue{DOTTED-LIST-ARGUMENTS:​CLARIFY}