81 lines
7.1 KiB
HTML
81 lines
7.1 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: Function VECTOR-PUSH, VECTOR-PUSH-EXTEND</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="f_vec_po.htm">
|
|
<LINK REL=UP HREF="c_arrays.htm">
|
|
<LINK REL=NEXT HREF="f_vecp.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="f_vec_po.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="c_arrays.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="f_vecp.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
|
|
|
<HR>
|
|
|
|
<A NAME="vector-push"><A NAME="vector-push-extend"><I>Function</I> <B>VECTOR-PUSH, VECTOR-PUSH-EXTEND</B></A></A> <P>
|
|
<P><B>Syntax:</B><P>
|
|
<P>
|
|
|
|
<B>vector-push</B> <I>new-element vector</I> => <I>new-index-p</I><P>
|
|
<P>
|
|
|
|
<B>vector-push-extend</B> <I>new-element vector <TT>&optional</TT> extension</I> => <I>new-index</I><P>
|
|
<P>
|
|
<P><B>Arguments and Values:</B><P>
|
|
<P>
|
|
<I>new-element</I>---an <A REL=DEFINITION HREF="26_glo_o.htm#object"><I>object</I></A>. <P>
|
|
<I>vector</I>---a <A REL=DEFINITION HREF="26_glo_v.htm#vector"><I>vector</I></A> with a <A REL=DEFINITION HREF="26_glo_f.htm#fill_pointer"><I>fill pointer</I></A>. <P>
|
|
<I>extension</I>---a positive <A REL=DEFINITION HREF="26_glo_i.htm#integer"><I>integer</I></A>. The default is <A REL=DEFINITION HREF="26_glo_i.htm#implementation-dependent"><I>implementation-dependent</I></A>. <P>
|
|
<I>new-index-p</I>---a <A REL=DEFINITION HREF="26_glo_v.htm#valid_array_index"><I>valid array index</I></A> for <I>vector</I>, or <A REL=DEFINITION HREF="a_nil.htm#nil"><B>nil</B></A>. <P>
|
|
<I>new-index</I>---a <A REL=DEFINITION HREF="26_glo_v.htm#valid_array_index"><I>valid array index</I></A> for <I>vector</I>. <P>
|
|
<P><B>Description:</B><P>
|
|
<P>
|
|
<A REL=DEFINITION HREF="#vector-push"><B>vector-push</B></A> and <A REL=DEFINITION HREF="#vector-push-extend"><B>vector-push-extend</B></A> store <I>new-element</I> in <I>vector</I>. <A REL=DEFINITION HREF="#vector-push"><B>vector-push</B></A> attempts to store <I>new-element</I> in the element of <I>vector</I> designated by the <A REL=DEFINITION HREF="26_glo_f.htm#fill_pointer"><I>fill pointer</I></A>, and to increase the <A REL=DEFINITION HREF="26_glo_f.htm#fill_pointer"><I>fill pointer</I></A> by one. If the <TT>(>= (fill-pointer </TT><I>vector</I><TT>) (array-dimension </TT><I>vector</I><TT> 0))</TT>, neither <I>vector</I> nor its <A REL=DEFINITION HREF="26_glo_f.htm#fill_pointer"><I>fill pointer</I></A> are affected. Otherwise, the store and increment take place and <A REL=DEFINITION HREF="#vector-push"><B>vector-push</B></A> returns the former value of the <A REL=DEFINITION HREF="26_glo_f.htm#fill_pointer"><I>fill pointer</I></A> which is one less than the one it leaves in <I>vector</I>. <P>
|
|
<A REL=DEFINITION HREF="#vector-push-extend"><B>vector-push-extend</B></A> is just like <A REL=DEFINITION HREF="#vector-push"><B>vector-push</B></A> except that if the <A REL=DEFINITION HREF="26_glo_f.htm#fill_pointer"><I>fill pointer</I></A> gets too large, <I>vector</I> is extended using <A REL=DEFINITION HREF="f_adjust.htm#adjust-array"><B>adjust-array</B></A> so that it can contain more elements. <I>Extension</I> is the minimum number of elements to be added to <I>vector</I> if it must be extended. <P>
|
|
<A REL=DEFINITION HREF="#vector-push"><B>vector-push</B></A> and <A REL=DEFINITION HREF="#vector-push-extend"><B>vector-push-extend</B></A> return the index of <I>new-element</I> in <I>vector</I>. If <TT>(>= (fill-pointer </TT><I>vector</I><TT>) (array-dimension </TT><I>vector</I><TT> 0))</TT>, <A REL=DEFINITION HREF="#vector-push"><B>vector-push</B></A> returns <A REL=DEFINITION HREF="a_nil.htm#nil"><B>nil</B></A>. <P>
|
|
<P><B>Examples:</B><P>
|
|
<P>
|
|
<PRE>
|
|
(vector-push (setq fable (list 'fable))
|
|
(setq fa (make-array 8
|
|
:fill-pointer 2
|
|
:initial-element 'first-one))) => 2
|
|
(fill-pointer fa) => 3
|
|
(eq (aref fa 2) fable) => <A REL=DEFINITION HREF="26_glo_t.htm#true">true</A>
|
|
(vector-push-extend #\X
|
|
(setq aa
|
|
(make-array 5
|
|
:element-type 'character
|
|
:adjustable t
|
|
:fill-pointer 3))) => 3
|
|
(fill-pointer aa) => 4
|
|
(vector-push-extend #\Y aa 4) => 4
|
|
(array-total-size aa) => at least 5
|
|
(vector-push-extend #\Z aa 4) => 5
|
|
(array-total-size aa) => 9 ;(or more)
|
|
</PRE>
|
|
</TT> <P>
|
|
<P><B>Affected By:</B><P>
|
|
The value of the <A REL=DEFINITION HREF="26_glo_f.htm#fill_pointer"><I>fill pointer</I></A>. <P>
|
|
How <I>vector</I> was created. <P>
|
|
<P><B>Exceptional Situations:</B><P>
|
|
<P>
|
|
An error of <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> <A REL=DEFINITION HREF="e_error.htm#error"><B>error</B></A> is signaled by <A REL=DEFINITION HREF="#vector-push-extend"><B>vector-push-extend</B></A> if it tries to extend <I>vector</I> and <I>vector</I> is not <A REL=DEFINITION HREF="26_glo_a.htm#actually_adjustable"><I>actually adjustable</I></A>. <P>
|
|
An error of <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> <A REL=DEFINITION HREF="e_error.htm#error"><B>error</B></A> is signaled if <I>vector</I> does not have a <A REL=DEFINITION HREF="26_glo_f.htm#fill_pointer"><I>fill pointer</I></A>. <P>
|
|
<P><B>See Also:</B><P>
|
|
<P>
|
|
<A REL=DEFINITION HREF="f_adju_1.htm#adjustable-array-p"><B>adjustable-array-p</B></A>, <A REL=DEFINITION HREF="f_fill_p.htm#fill-pointer"><B>fill-pointer</B></A>, <A REL=DEFINITION HREF="f_vec_po.htm#vector-pop"><B>vector-pop</B></A> <P>
|
|
<P><B>Notes:</B> None.
|
|
<P>
|
|
<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>
|