390 lines
No EOL
7.4 KiB
HTML
390 lines
No EOL
7.4 KiB
HTML
<!DOCTYPE HTML>
|
|
<HTML LANG="en-us"
|
|
><HEAD
|
|
><TITLE
|
|
>butlast, nbutlast | Common Lisp Nova Spec</TITLE
|
|
><META CHARSET="US-ASCII"
|
|
><LINK REL="canonical" HREF="f_butlast.html"
|
|
><LINK REL="next" HREF="f_last.html" TYPE="text/html" TITLE="last"
|
|
><LINK REL="prev" HREF="f_revappend.html" TYPE="text/html" TITLE="revappend, nreconc"
|
|
><LINK REL="up" HREF="14_2_Conses_Dictionary.html" TYPE="text/html" TITLE="14.2 Conses Dictionary"
|
|
><LINK REL="start" HREF="index.html" TYPE="text/html" TITLE="Common Lisp Nova Spec"
|
|
><META NAME="VIEWPORT" CONTENT="width=device-width, initial-scale=1.0"
|
|
><LINK REL="STYLESHEET" HREF="dpans.css%3F3909942064.css"
|
|
><SCRIPT SRC="dpans.js%3F3909942064"
|
|
></SCRIPT
|
|
><SCRIPT SRC="apropos.js%3F3909942064"
|
|
></SCRIPT
|
|
></HEAD
|
|
><BODY
|
|
><DIV
|
|
><DIV CLASS="topnav"
|
|
><DIV CLASS="breadcrumb"
|
|
><SPAN CLASS="breadcrumb-item"
|
|
><A HREF="index.html"
|
|
>Common Lisp Nova Spec</A
|
|
></SPAN
|
|
> <SPAN CLASS="breadcrumb-item"
|
|
>→ <A HREF="14_Conses.html"
|
|
>14. Conses</A
|
|
></SPAN
|
|
> <SPAN CLASS="breadcrumb-item"
|
|
>→ <A HREF="14_2_Conses_Dictionary.html"
|
|
>14.2 Conses Dictionary</A
|
|
></SPAN
|
|
> <SPAN CLASS="breadcrumb-item"
|
|
>→ <A HREF="f_butlast.html"
|
|
>butlast, nbutlast</A
|
|
></SPAN
|
|
></DIV
|
|
><DIV CLASS="apropos"
|
|
><DIV CLASS="apropos-io"
|
|
><A HREF="f_revappend.html" CLASS="prev"
|
|
>←</A
|
|
><SPAN ID="apropos-label"
|
|
>Apropos </SPAN
|
|
><INPUT ID="apropos" AUTOFOCUS="AUTOFOCUS" PLACEHOLDER="Type here to search" ONINPUT="aproposInput(this);" ONKEYUP="aproposKeyup(event);" ONCHANGE="aproposChange(this);" ONFOCUS="aproposFocus(this);" ONFOCUSOUT="aproposFocusout(this);"
|
|
><A HREF="f_last.html" CLASS="next"
|
|
>→</A
|
|
></DIV
|
|
><DIV ID="apropos-res"
|
|
></DIV
|
|
></DIV
|
|
></DIV
|
|
><DIV CLASS="matter"
|
|
><DIV CLASS="com"
|
|
><DIV CLASS="begincom"
|
|
><HR
|
|
><TABLE WIDTH="100%" CELLSPACING="0" CELLPADDING="0"
|
|
><TR
|
|
><TD ALIGN="LEFT" VALIGN="BASELINE" WIDTH="100%" CLASS="name"
|
|
><SPAN CLASS="idx" DATA-KIND="idxref" DATA-TERM="butlast, nbutlast"
|
|
></SPAN
|
|
><B
|
|
>butlast, nbutlast</B
|
|
></TD
|
|
><TD ALIGN="RIGHT" VALIGN="BASELINE" WIDTH="0" NOWRAP="NOWRAP" CLASS="ftype"
|
|
><I
|
|
>Function</I
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
><HR
|
|
></DIV
|
|
><UL CLASS="subtoc"
|
|
></UL
|
|
><DL
|
|
><DT
|
|
><B
|
|
>Syntax</B
|
|
></DT
|
|
><DD
|
|
><P CLASS="j"
|
|
><B
|
|
>butlast</B
|
|
> <SPAN CLASS="cmssi"
|
|
>list</SPAN
|
|
> <SPAN CLASS="cmtt"
|
|
>&optional</SPAN
|
|
> <SPAN CLASS="cmssi"
|
|
>n</SPAN
|
|
> <SPAN CLASS="arrow"
|
|
>→</SPAN
|
|
> <SPAN CLASS="cmssi"
|
|
>result-list</SPAN
|
|
></P
|
|
><P CLASS="j"
|
|
><B
|
|
>nbutlast</B
|
|
> <SPAN CLASS="cmssi"
|
|
>list</SPAN
|
|
> <SPAN CLASS="cmtt"
|
|
>&optional</SPAN
|
|
> <SPAN CLASS="cmssi"
|
|
>n</SPAN
|
|
> <SPAN CLASS="arrow"
|
|
>→</SPAN
|
|
> <SPAN CLASS="cmssi"
|
|
>result-list</SPAN
|
|
></P
|
|
></DD
|
|
><DT
|
|
><B
|
|
>Arguments and Values</B
|
|
></DT
|
|
><DD
|
|
><P CLASS="j"
|
|
><VAR CLASS="param"
|
|
>list</VAR
|
|
> — a <A HREF="26_1_Glossary.html#list"
|
|
><EM CLASS="term"
|
|
>list</EM
|
|
></A
|
|
>, which might be a <A HREF="26_1_Glossary.html#dotted_list"
|
|
><EM CLASS="term"
|
|
>dotted list</EM
|
|
></A
|
|
> but must not be a <A HREF="26_1_Glossary.html#circular_list"
|
|
><EM CLASS="term"
|
|
>circular list</EM
|
|
></A
|
|
>. </P
|
|
><P CLASS="j"
|
|
><VAR CLASS="param"
|
|
>n</VAR
|
|
> — a non-negative <A HREF="26_1_Glossary.html#integer"
|
|
><EM CLASS="term"
|
|
>integer</EM
|
|
></A
|
|
>. </P
|
|
><P CLASS="j"
|
|
><VAR CLASS="param"
|
|
>result-list</VAR
|
|
> — a <A HREF="26_1_Glossary.html#list"
|
|
><EM CLASS="term"
|
|
>list</EM
|
|
></A
|
|
>.</P
|
|
></DD
|
|
><DT
|
|
><B
|
|
>Description</B
|
|
></DT
|
|
><DD
|
|
><P CLASS="j"
|
|
><A HREF="f_butlast.html" CLASS="funref"
|
|
><B
|
|
>butlast</B
|
|
></A
|
|
> returns a copy of <VAR CLASS="param"
|
|
>list</VAR
|
|
> from which the last <VAR CLASS="param"
|
|
>n</VAR
|
|
> conses have been omitted. If <VAR CLASS="param"
|
|
>n</VAR
|
|
> is not supplied, its value is 1. If there are fewer than <VAR CLASS="param"
|
|
>n</VAR
|
|
> conses in <VAR CLASS="param"
|
|
>list</VAR
|
|
>, <SPAN CLASS="misc"
|
|
><B
|
|
>nil</B
|
|
></SPAN
|
|
> is returned and, in the case of <A HREF="f_butlast.html" CLASS="funref"
|
|
><B
|
|
>nbutlast</B
|
|
></A
|
|
>, <VAR CLASS="param"
|
|
>list</VAR
|
|
> is not modified. </P
|
|
><P CLASS="j"
|
|
><A HREF="f_butlast.html" CLASS="funref"
|
|
><B
|
|
>nbutlast</B
|
|
></A
|
|
> is like <A HREF="f_butlast.html" CLASS="funref"
|
|
><B
|
|
>butlast</B
|
|
></A
|
|
>, but <A HREF="f_butlast.html" CLASS="funref"
|
|
><B
|
|
>nbutlast</B
|
|
></A
|
|
> may modify <VAR CLASS="param"
|
|
>list</VAR
|
|
>. It changes the <A HREF="26_1_Glossary.html#cdr"
|
|
><EM CLASS="term"
|
|
>cdr</EM
|
|
></A
|
|
> of the <A HREF="26_1_Glossary.html#cons"
|
|
><EM CLASS="term"
|
|
>cons</EM
|
|
></A
|
|
> <VAR CLASS="param"
|
|
>n</VAR
|
|
>+1 from the end of the <VAR CLASS="param"
|
|
>list</VAR
|
|
> to <SPAN CLASS="misc"
|
|
><B
|
|
>nil</B
|
|
></SPAN
|
|
>.</P
|
|
></DD
|
|
><DT
|
|
><B
|
|
>Examples</B
|
|
></DT
|
|
><DD
|
|
><PRE CLASS="screen"
|
|
>(setq lst '(1 2 3 4 5 6 7 8 9)) <SPAN CLASS="cmsy"
|
|
><SPAN CLASS="arrow"
|
|
>→</SPAN
|
|
></SPAN
|
|
> (1 2 3 4 5 6 7 8 9)
|
|
(butlast lst) <SPAN CLASS="cmsy"
|
|
><SPAN CLASS="arrow"
|
|
>→</SPAN
|
|
></SPAN
|
|
> (1 2 3 4 5 6 7 8)
|
|
(butlast lst 5) <SPAN CLASS="cmsy"
|
|
><SPAN CLASS="arrow"
|
|
>→</SPAN
|
|
></SPAN
|
|
> (1 2 3 4)
|
|
(butlast lst (+ 5 5)) <SPAN CLASS="cmsy"
|
|
><SPAN CLASS="arrow"
|
|
>→</SPAN
|
|
></SPAN
|
|
> NIL
|
|
lst <SPAN CLASS="cmsy"
|
|
><SPAN CLASS="arrow"
|
|
>→</SPAN
|
|
></SPAN
|
|
> (1 2 3 4 5 6 7 8 9)
|
|
(nbutlast lst 3) <SPAN CLASS="cmsy"
|
|
><SPAN CLASS="arrow"
|
|
>→</SPAN
|
|
></SPAN
|
|
> (1 2 3 4 5 6)
|
|
lst <SPAN CLASS="cmsy"
|
|
><SPAN CLASS="arrow"
|
|
>→</SPAN
|
|
></SPAN
|
|
> (1 2 3 4 5 6)
|
|
(nbutlast lst 99) <SPAN CLASS="cmsy"
|
|
><SPAN CLASS="arrow"
|
|
>→</SPAN
|
|
></SPAN
|
|
> NIL
|
|
lst <SPAN CLASS="cmsy"
|
|
><SPAN CLASS="arrow"
|
|
>→</SPAN
|
|
></SPAN
|
|
> (1 2 3 4 5 6)
|
|
(butlast '(a b c d)) <SPAN CLASS="cmsy"
|
|
><SPAN CLASS="arrow"
|
|
>→</SPAN
|
|
></SPAN
|
|
> (A B C)
|
|
(butlast '((a b) (c d))) <SPAN CLASS="cmsy"
|
|
><SPAN CLASS="arrow"
|
|
>→</SPAN
|
|
></SPAN
|
|
> ((A B))
|
|
(butlast '(a)) <SPAN CLASS="cmsy"
|
|
><SPAN CLASS="arrow"
|
|
>→</SPAN
|
|
></SPAN
|
|
> NIL
|
|
(butlast nil) <SPAN CLASS="cmsy"
|
|
><SPAN CLASS="arrow"
|
|
>→</SPAN
|
|
></SPAN
|
|
> NIL
|
|
(setq foo (list 'a 'b 'c 'd)) <SPAN CLASS="cmsy"
|
|
><SPAN CLASS="arrow"
|
|
>→</SPAN
|
|
></SPAN
|
|
> (A B C D)
|
|
(nbutlast foo) <SPAN CLASS="cmsy"
|
|
><SPAN CLASS="arrow"
|
|
>→</SPAN
|
|
></SPAN
|
|
> (A B C)
|
|
foo <SPAN CLASS="cmsy"
|
|
><SPAN CLASS="arrow"
|
|
>→</SPAN
|
|
></SPAN
|
|
> (A B C)
|
|
(nbutlast (list 'a)) <SPAN CLASS="cmsy"
|
|
><SPAN CLASS="arrow"
|
|
>→</SPAN
|
|
></SPAN
|
|
> NIL
|
|
(nbutlast '()) <SPAN CLASS="cmsy"
|
|
><SPAN CLASS="arrow"
|
|
>→</SPAN
|
|
></SPAN
|
|
> NIL</PRE
|
|
></DD
|
|
><DT
|
|
><B
|
|
>Exceptional Situations</B
|
|
></DT
|
|
><DD
|
|
><P CLASS="j"
|
|
>Should signal an error of <A HREF="26_1_Glossary.html#type"
|
|
><EM CLASS="term"
|
|
>type</EM
|
|
></A
|
|
> <A HREF="t_type-error.html" CLASS="typeref"
|
|
><B
|
|
>type-error</B
|
|
></A
|
|
> if <VAR CLASS="param"
|
|
>list</VAR
|
|
> is not a <A HREF="26_1_Glossary.html#proper_list"
|
|
><EM CLASS="term"
|
|
>proper list</EM
|
|
></A
|
|
> or a <A HREF="26_1_Glossary.html#dotted_list"
|
|
><EM CLASS="term"
|
|
>dotted list</EM
|
|
></A
|
|
>. Should signal an error of <A HREF="26_1_Glossary.html#type"
|
|
><EM CLASS="term"
|
|
>type</EM
|
|
></A
|
|
> <A HREF="t_type-error.html" CLASS="typeref"
|
|
><B
|
|
>type-error</B
|
|
></A
|
|
> if <VAR CLASS="param"
|
|
>n</VAR
|
|
> is not a non-negative <A HREF="26_1_Glossary.html#integer"
|
|
><EM CLASS="term"
|
|
>integer</EM
|
|
></A
|
|
>.</P
|
|
></DD
|
|
><DT
|
|
><B
|
|
>Notes</B
|
|
></DT
|
|
><DD
|
|
><PRE CLASS="screen"
|
|
>(butlast <VAR CLASS="param"
|
|
>list</VAR
|
|
> <VAR CLASS="param"
|
|
>n</VAR
|
|
>) <SPAN CLASS="cmsy"
|
|
><SPAN STYLE="font-size:16px;vertical-align:-2px"
|
|
>≡</SPAN
|
|
></SPAN
|
|
> (ldiff <VAR CLASS="param"
|
|
>list</VAR
|
|
> (last <VAR CLASS="param"
|
|
>list</VAR
|
|
> <VAR CLASS="param"
|
|
>n</VAR
|
|
>))</PRE
|
|
></DD
|
|
></DL
|
|
></DIV
|
|
></DIV
|
|
><DIV CLASS="footer"
|
|
><DIV CLASS="btmnav"
|
|
><A HREF="f_revappend.html" CLASS="prev"
|
|
>←</A
|
|
><A HREF="f_last.html" CLASS="next"
|
|
>→</A
|
|
></DIV
|
|
><DIV CLASS="trail"
|
|
>Conversion to HTML copyright 2023 by Gilbert Baumann</DIV
|
|
></DIV
|
|
></DIV
|
|
><SCRIPT
|
|
>domReady();</SCRIPT
|
|
></BODY
|
|
></HTML
|
|
> |