1
0
Fork 0
cl-sites/HyperSpec-7-0/HyperSpec/Body/f_rd_seq.htm

65 lines
6.7 KiB
HTML
Raw Normal View History

2024-04-01 10:24:07 +02:00
<!-- 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 READ-SEQUENCE</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_wr_stg.htm">
<LINK REL=UP HREF="c_stream.htm">
<LINK REL=NEXT HREF="f_wr_seq.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_wr_stg.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="c_stream.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="f_wr_seq.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<A NAME="read-sequence"><I>Function</I> <B>READ-SEQUENCE</B></A> <P>
<P><B>Syntax:</B><P>
<P>
<B>read-sequence</B> <I>sequence stream <TT>&amp;key</TT> start end</I> =&gt; <I>position</I><P>
<P>
<I>sequence</I>---a <A REL=DEFINITION HREF="26_glo_s.htm#sequence"><I>sequence</I></A>. <P>
<I>stream</I>---an <A REL=DEFINITION HREF="26_glo_i.htm#input"><I>input</I></A> <A REL=DEFINITION HREF="26_glo_s.htm#stream"><I>stream</I></A>. <P>
<I>start</I>, <I>end</I>---<A REL=DEFINITION HREF="26_glo_b.htm#bounding_index_designator"><I>bounding index designators</I></A> of <I>sequence</I>. The defaults for <I>start</I> and <I>end</I> are <TT>0</TT> and <A REL=DEFINITION HREF="a_nil.htm#nil"><B>nil</B></A>, respectively. <P>
<I>position</I>---an <A REL=DEFINITION HREF="26_glo_i.htm#integer"><I>integer</I></A> greater than or equal to zero, and less than or equal to the <A REL=DEFINITION HREF="26_glo_l.htm#length"><I>length</I></A> of the <I>sequence</I>. <P>
<P><B>Description:</B><P>
<P>
Destructively modifies <I>sequence</I> by replacing the <A REL=DEFINITION HREF="26_glo_e.htm#element"><I>elements</I></A> of <I>sequence</I> <A REL=DEFINITION HREF="26_glo_b.htm#bounded"><I>bounded</I></A> by <I>start</I> and <I>end</I> with <A REL=DEFINITION HREF="26_glo_e.htm#element"><I>elements</I></A> read from <I>stream</I>. <P>
<I>Sequence</I> is destructively modified by copying successive <A REL=DEFINITION HREF="26_glo_e.htm#element"><I>elements</I></A> into it from <I>stream</I>. If the <A REL=DEFINITION HREF="26_glo_e.htm#end_of_file"><I>end of file</I></A> for <I>stream</I> is reached before copying all <A REL=DEFINITION HREF="26_glo_e.htm#element"><I>elements</I></A> of the subsequence, then the extra <A REL=DEFINITION HREF="26_glo_e.htm#element"><I>elements</I></A> near the end of <I>sequence</I> are not updated. <P>
<I>Position</I> is the index of the first <A REL=DEFINITION HREF="26_glo_e.htm#element"><I>element</I></A> of <I>sequence</I> that was not updated, which might be less than <I>end</I> because the <A REL=DEFINITION HREF="26_glo_e.htm#end_of_file"><I>end of file</I></A> was reached. <P>
<P><B>Examples:</B><P>
<P>
<PRE>
(defvar *data* (make-array 15 :initial-element nil))
(values (read-sequence *data* (make-string-input-stream &quot;test string&quot;)) *data*)
=&gt; 11, #(#\t #\e #\s #\t #\Space #\s #\t #\r #\i #\n #\g NIL NIL NIL NIL)
</PRE>
</TT> <P>
<P><B>Side Effects:</B><P>
<P>
Modifies <I>stream</I> and <I>sequence</I>. <P>
<P><B>Affected By:</B> None.
<P>
<P><B>Exceptional Situations:</B><P>
<P>
Should be prepared to signal an error of <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> <A REL=DEFINITION HREF="e_tp_err.htm#type-error"><B>type-error</B></A> if <I>sequence</I> is not a <A REL=DEFINITION HREF="26_glo_p.htm#proper_sequence"><I>proper sequence</I></A>. Should signal an error of <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> <A REL=DEFINITION HREF="e_tp_err.htm#type-error"><B>type-error</B></A> if <I>start</I> is not a non-negative <A REL=DEFINITION HREF="26_glo_i.htm#integer"><I>integer</I></A>. Should signal an error of <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> <A REL=DEFINITION HREF="e_tp_err.htm#type-error"><B>type-error</B></A> if <I>end</I> is not a non-negative <A REL=DEFINITION HREF="26_glo_i.htm#integer"><I>integer</I></A> or <A REL=DEFINITION HREF="a_nil.htm#nil"><B>nil</B></A>. <P>
Might signal an error of <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> <A REL=DEFINITION HREF="e_tp_err.htm#type-error"><B>type-error</B></A> if an <A REL=DEFINITION HREF="26_glo_e.htm#element"><I>element</I></A> read from the <I>stream</I> is not a member of the <A REL=DEFINITION HREF="26_glo_e.htm#element_type"><I>element type</I></A> of the <I>sequence</I>. <P>
<P><B>See Also:</B><P>
<P>
<A REL=CHILD HREF="03_ba.htm">Section 3.2.1 (Compiler Terminology)</A>, <A REL=DEFINITION HREF="f_wr_seq.htm#write-sequence"><B>write-sequence</B></A>, <A REL=DEFINITION HREF="f_rd_lin.htm#read-line"><B>read-line</B></A> <P>
<P><B>Notes:</B><P>
<P>
<A REL=DEFINITION HREF="#read-sequence"><B>read-sequence</B></A> is identical in effect to iterating over the indicated subsequence and reading one <A REL=DEFINITION HREF="26_glo_e.htm#element"><I>element</I></A> at a time from <I>stream</I> and storing it into <I>sequence</I>, but may be more efficient than the equivalent loop. An efficient implementation is more likely to exist for the case where the <I>sequence</I> is a <A REL=DEFINITION HREF="26_glo_v.htm#vector"><I>vector</I></A> with the same <A REL=DEFINITION HREF="26_glo_e.htm#element_type"><I>element type</I></A> as the <I>stream</I>. <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>