126 lines
7.2 KiB
HTML
126 lines
7.2 KiB
HTML
<!-- Common Lisp HyperSpec (TM), version 7.0 generated by Kent M. Pitman on Mon, 11-Apr-2005 2:31am EDT -->
|
|
<HTML>
|
|
<HEAD>
|
|
<TITLE>CLHS: Accessor FIRST, SECOND, THIRD, FOURTH...</TITLE>
|
|
<LINK HREF="../Data/clhs.css" REL="stylesheet" TYPE="text/css" />
|
|
<META HTTP-EQUIV="Author" CONTENT="Kent M. Pitman">
|
|
<META HTTP-EQUIV="Organization" CONTENT="LispWorks Ltd.">
|
|
<LINK REL=TOP HREF="../Front/index.htm">
|
|
<LINK REL=COPYRIGHT HREF="../Front/Help.htm#Legal">
|
|
<LINK REL=DISCLAIMER HREF="../Front/Help.htm#Disclaimer">
|
|
<LINK REL=PREV HREF="m_pop.htm">
|
|
<LINK REL=UP HREF="c_conses.htm">
|
|
<LINK REL=NEXT HREF="f_nth.htm">
|
|
</HEAD>
|
|
<BODY>
|
|
<H1><A REV=MADE HREF="http://www.lispworks.com/"><IMG WIDTH=80 HEIGHT=65 ALT="[LISPWORKS]" SRC="../Graphics/LWSmall.gif" ALIGN=Bottom></A><A REL=TOP HREF="../Front/index.htm"><IMG WIDTH=237 HEIGHT=65 ALT="[Common Lisp HyperSpec (TM)]" SRC="../Graphics/CLHS_Sm.gif" ALIGN=Bottom></A> <A REL=PREV HREF="m_pop.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="c_conses.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="f_nth.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
|
|
|
<HR>
|
|
|
|
<A NAME="first"><A NAME="second"><A NAME="third"><A NAME="fourth"><A NAME="fifth"><A NAME="sixth"><A NAME="seventh"><A NAME="eighth"><A NAME="ninth"><A NAME="tenth"><I>Accessor</I> <B>FIRST, SECOND, THIRD, FOURTH, FIFTH, SIXTH, SEVENTH, EIGHTH, NINTH, TENTH</B></A></A></A></A></A></A></A></A></A></A> <P>
|
|
<P><B>Syntax:</B><P>
|
|
<P>
|
|
|
|
<B>first</B> <I>list</I> => <I>object</I><P>
|
|
|
|
<B>second</B> <I>list</I> => <I>object</I><P>
|
|
|
|
<B>third</B> <I>list</I> => <I>object</I><P>
|
|
|
|
<B>fourth</B> <I>list</I> => <I>object</I><P>
|
|
|
|
<B>fifth</B> <I>list</I> => <I>object</I><P>
|
|
|
|
<B>sixth</B> <I>list</I> => <I>object</I><P>
|
|
|
|
<B>seventh</B> <I>list</I> => <I>object</I><P>
|
|
|
|
<B>eighth</B> <I>list</I> => <I>object</I><P>
|
|
|
|
<B>ninth</B> <I>list</I> => <I>object</I><P>
|
|
|
|
<B>tenth</B> <I>list</I> => <I>object</I><P>
|
|
|
|
<TT>(setf (</TT><B>first</B> <I>list</I><TT>) </TT><I>new-object</I><TT>)</TT><P>
|
|
|
|
<TT>(setf (</TT><B>second</B> <I>list</I><TT>) </TT><I>new-object</I><TT>)</TT><P>
|
|
|
|
<TT>(setf (</TT><B>third</B> <I>list</I><TT>) </TT><I>new-object</I><TT>)</TT><P>
|
|
|
|
<TT>(setf (</TT><B>fourth</B> <I>list</I><TT>) </TT><I>new-object</I><TT>)</TT><P>
|
|
|
|
<TT>(setf (</TT><B>fifth</B> <I>list</I><TT>) </TT><I>new-object</I><TT>)</TT><P>
|
|
|
|
<TT>(setf (</TT><B>sixth</B> <I>list</I><TT>) </TT><I>new-object</I><TT>)</TT><P>
|
|
|
|
<TT>(setf (</TT><B>seventh</B> <I>list</I><TT>) </TT><I>new-object</I><TT>)</TT><P>
|
|
|
|
<TT>(setf (</TT><B>eighth</B> <I>list</I><TT>) </TT><I>new-object</I><TT>)</TT><P>
|
|
|
|
<TT>(setf (</TT><B>ninth</B> <I>list</I><TT>) </TT><I>new-object</I><TT>)</TT><P>
|
|
|
|
<TT>(setf (</TT><B>tenth</B> <I>list</I><TT>) </TT><I>new-object</I><TT>)</TT><P>
|
|
<P>
|
|
<P><B>Arguments and Values:</B><P>
|
|
<P>
|
|
<I>list</I>---a <A REL=DEFINITION HREF="26_glo_l.htm#list"><I>list</I></A>, which might be a <A REL=DEFINITION HREF="26_glo_d.htm#dotted_list"><I>dotted list</I></A> or a <A REL=DEFINITION HREF="26_glo_c.htm#circular_list"><I>circular list</I></A>. <P>
|
|
<I>object</I>, <I>new-object</I>---an <I>object</I>. <P>
|
|
<P><B>Description:</B><P>
|
|
<P>
|
|
The functions <A REL=DEFINITION HREF="#first"><B>first</B></A>, <A REL=DEFINITION HREF="#second"><B>second</B></A>, <A REL=DEFINITION HREF="#third"><B>third</B></A>, <A REL=DEFINITION HREF="#fourth"><B>fourth</B></A>, <A REL=DEFINITION HREF="#fifth"><B>fifth</B></A>, <A REL=DEFINITION HREF="#sixth"><B>sixth</B></A>, <A REL=DEFINITION HREF="#seventh"><B>seventh</B></A>, <A REL=DEFINITION HREF="#eighth"><B>eighth</B></A>, <A REL=DEFINITION HREF="#ninth"><B>ninth</B></A>, and <A REL=DEFINITION HREF="#tenth"><B>tenth</B></A> <I>access</I> the first, second, third, fourth, fifth, sixth, seventh, eighth, ninth, and tenth <A REL=DEFINITION HREF="26_glo_e.htm#element"><I>elements</I></A> of <I>list</I>, respectively. Specifically, <P>
|
|
<PRE>
|
|
(first list) == (car list)
|
|
(second list) == (car (cdr list))
|
|
(third list) == (car (cddr list))
|
|
(fourth list) == (car (cdddr list))
|
|
(fifth list) == (car (cddddr list))
|
|
(sixth list) == (car (cdr (cddddr list)))
|
|
(seventh list) == (car (cddr (cddddr list)))
|
|
(eighth list) == (car (cdddr (cddddr list)))
|
|
(ninth list) == (car (cddddr (cddddr list)))
|
|
(tenth list) == (car (cdr (cddddr (cddddr list))))
|
|
</PRE>
|
|
</TT> <P>
|
|
<A REL=DEFINITION HREF="m_setf_.htm#setf"><B>setf</B></A> can also be used with any of these functions to change an existing component. The same equivalences apply. For example: <P>
|
|
<PRE>
|
|
(setf (fifth list) new-object) == (setf (car (cddddr list)) new-object)
|
|
</PRE>
|
|
</TT> <P>
|
|
<P><B>Examples:</B><P>
|
|
<P>
|
|
<PRE>
|
|
(setq lst '(1 2 3 (4 5 6) ((V)) vi 7 8 9 10))
|
|
=> (1 2 3 (4 5 6) ((V)) VI 7 8 9 10)
|
|
(first lst) => 1
|
|
(tenth lst) => 10
|
|
(fifth lst) => ((V))
|
|
(second (fourth lst)) => 5
|
|
(sixth '(1 2 3)) => NIL
|
|
(setf (fourth lst) "four") => "four"
|
|
lst => (1 2 3 "four" ((V)) VI 7 8 9 10)
|
|
</PRE>
|
|
</TT> <P>
|
|
<P><B>Side Effects:</B> None.
|
|
<P>
|
|
<P><B>Affected By:</B> None.
|
|
<P>
|
|
<P><B>Exceptional Situations:</B> None.
|
|
<P>
|
|
<P><B>See Also:</B><P>
|
|
<P>
|
|
<A REL=DEFINITION HREF="f_car_c.htm#car"><B>car</B></A>, <A REL=DEFINITION HREF="f_nth.htm#nth"><B>nth</B></A> <P>
|
|
<P><B>Notes:</B><P>
|
|
<P>
|
|
<A REL=DEFINITION HREF="#first"><B>first</B></A> is functionally equivalent to <A REL=DEFINITION HREF="f_car_c.htm#car"><B>car</B></A>, <A REL=DEFINITION HREF="#second"><B>second</B></A> is functionally equivalent to <A REL=DEFINITION HREF="f_car_c.htm#cadr"><B>cadr</B></A>, <A REL=DEFINITION HREF="#third"><B>third</B></A> is functionally equivalent to <A REL=DEFINITION HREF="f_car_c.htm#caddr"><B>caddr</B></A>, and <A REL=DEFINITION HREF="#fourth"><B>fourth</B></A> is functionally equivalent to <A REL=DEFINITION HREF="f_car_c.htm#cadddr"><B>cadddr</B></A>. <P>
|
|
The ordinal numbering used here is one-origin, as opposed to the zero-origin numbering used by <A REL=DEFINITION HREF="f_nth.htm#nth"><B>nth</B></A>: <P>
|
|
<PRE>
|
|
(fifth x) == (nth 4 x)
|
|
</PRE>
|
|
</TT> <P>
|
|
<P><HR>The following <A REL=META HREF="../Front/X3J13Iss.htm">X3J13 cleanup issue</A>, <I>not part of the specification</I>, applies to this section:<P><UL><LI> <A REL=CHILD HREF="../Issues/iss138.htm">DOTTED-LIST-ARGUMENTS:CLARIFY</A><P></UL><HR>
|
|
|
|
<A REL=NAVIGATOR HREF="../Front/StartPts.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Starting Points]" SRC="../Graphics/StartPts.gif" ALIGN=Bottom></A><A REL=TOC HREF="../Front/Contents.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Contents]" SRC="../Graphics/Contents.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Master.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Index]" SRC="../Graphics/Index.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Symbol.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Symbols]" SRC="../Graphics/Symbols.gif" ALIGN=Bottom></A><A REL=GLOSSARY HREF="../Body/26_a.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Glossary]" SRC="../Graphics/Glossary.gif" ALIGN=Bottom></A><A HREF="../Front/X3J13Iss.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Issues]" SRC="../Graphics/Issues.gif" ALIGN=Bottom></A><BR>
|
|
|
|
<A REL=COPYRIGHT HREF="../Front/Help.htm#Legal"><I>Copyright 1996-2005, LispWorks Ltd. All rights reserved.</I></A><P>
|
|
</BODY>
|
|
</HTML>
|