75 lines
7.9 KiB
HTML
75 lines
7.9 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: Macro WITH-INPUT-FROM-STRING</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_mk_s_2.htm">
|
||
|
<LINK REL=UP HREF="c_stream.htm">
|
||
|
<LINK REL=NEXT HREF="m_w_out_.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_mk_s_2.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="m_w_out_.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
||
|
|
||
|
<HR>
|
||
|
|
||
|
<A NAME="with-input-from-string"><I>Macro</I> <B>WITH-INPUT-FROM-STRING</B></A> <P>
|
||
|
<P>
|
||
|
<P><B>Syntax:</B><P>
|
||
|
<P>
|
||
|
|
||
|
<B>with-input-from-string</B> <I>(var string <TT>&key</TT> index start end) <I>declaration</I><B>*</B> <I>form</I><B>*</B></I><P> => <I><I>result</I><B>*</B></I><P>
|
||
|
<P>
|
||
|
<P><B>Arguments and Values:</B><P>
|
||
|
<P>
|
||
|
<I>var</I>---a <A REL=DEFINITION HREF="26_glo_v.htm#variable"><I>variable</I></A> <A REL=DEFINITION HREF="26_glo_n.htm#name"><I>name</I></A>. <P>
|
||
|
<I>string</I>---a <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A>; evaluated to produce a <A REL=DEFINITION HREF="26_glo_s.htm#string"><I>string</I></A>. <P>
|
||
|
<I>index</I>---a <A REL=DEFINITION HREF="26_glo_p.htm#place"><I>place</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>string</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. <I>declaration</I>---a <A REL=DEFINITION HREF="s_declar.htm#declare"><B>declare</B></A> <A REL=DEFINITION HREF="26_glo_e.htm#expression"><I>expression</I></A>; not evaluated. <P>
|
||
|
<I>forms</I>---an <A REL=DEFINITION HREF="26_glo_i.htm#implicit_progn"><I>implicit progn</I></A>. <P>
|
||
|
<I>result</I>---the <A REL=DEFINITION HREF="26_glo_v.htm#value"><I>values</I></A> returned by the <I>forms</I>. <P>
|
||
|
<P><B>Description:</B><P>
|
||
|
<P>
|
||
|
Creates an <A REL=DEFINITION HREF="26_glo_i.htm#input"><I>input</I></A> <A REL=DEFINITION HREF="26_glo_s.htm#string_stream"><I>string stream</I></A>, provides an opportunity to perform operations on the <A REL=DEFINITION HREF="26_glo_s.htm#stream"><I>stream</I></A> (returning zero or more <A REL=DEFINITION HREF="26_glo_v.htm#value"><I>values</I></A>), and then closes the <A REL=DEFINITION HREF="26_glo_s.htm#string_stream"><I>string stream</I></A>. <P>
|
||
|
<I>String</I> is evaluated first, and <I>var</I> is bound to a character <A REL=DEFINITION HREF="26_glo_i.htm#input"><I>input</I></A> <A REL=DEFINITION HREF="26_glo_s.htm#string_stream"><I>string stream</I></A> that supplies <A REL=DEFINITION HREF="26_glo_c.htm#character"><I>characters</I></A> from the subsequence of the resulting <A REL=DEFINITION HREF="26_glo_s.htm#string"><I>string</I></A> <A REL=DEFINITION HREF="26_glo_b.htm#bounded"><I>bounded</I></A> by <I>start</I> and <I>end</I>. The body is executed as an <A REL=DEFINITION HREF="26_glo_i.htm#implicit_progn"><I>implicit progn</I></A>. <P>
|
||
|
The <A REL=DEFINITION HREF="26_glo_i.htm#input"><I>input</I></A> <A REL=DEFINITION HREF="26_glo_s.htm#string_stream"><I>string stream</I></A> is automatically closed on exit from <A REL=DEFINITION HREF="#with-input-from-string"><B>with-input-from-string</B></A>, no matter whether the exit is normal or abnormal. The <A REL=DEFINITION HREF="26_glo_i.htm#input"><I>input</I></A> <A REL=DEFINITION HREF="26_glo_s.htm#string_stream"><I>string stream</I></A> to which the <A REL=DEFINITION HREF="26_glo_v.htm#variable"><I>variable</I></A> <I>var</I> is <A REL=DEFINITION HREF="26_glo_b.htm#bound"><I>bound</I></A> has <A REL=DEFINITION HREF="26_glo_d.htm#dynamic_extent"><I>dynamic extent</I></A>; its <A REL=DEFINITION HREF="26_glo_e.htm#extent"><I>extent</I></A> ends when the <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A> is exited. <P>
|
||
|
The <I>index</I> is a pointer within the <I>string</I> to be advanced. If <A REL=DEFINITION HREF="#with-input-from-string"><B>with-input-from-string</B></A> is exited normally, then <I>index</I> will have as its <A REL=DEFINITION HREF="26_glo_v.htm#value"><I>value</I></A> the index into the <I>string</I> indicating the first character not read which is <TT>(length </TT><I>string</I><TT>)</TT> if all characters were used. The place specified by <I>index</I> is not updated as reading progresses, but only at the end of the operation. <P>
|
||
|
<I>start</I> and <I>index</I> may both specify the same variable, which is a pointer within the <I>string</I> to be advanced, perhaps repeatedly by some containing loop. <P>
|
||
|
The consequences are undefined if an attempt is made to <A REL=DEFINITION HREF="26_glo_a.htm#assign"><I>assign</I></A> the <A REL=DEFINITION HREF="26_glo_v.htm#variable"><I>variable</I></A> <I>var</I>. <P>
|
||
|
<P><B>Examples:</B><P>
|
||
|
|
||
|
<PRE>
|
||
|
(with-input-from-string (s "XXX1 2 3 4xxx"
|
||
|
:index ind
|
||
|
:start 3 :end 10)
|
||
|
(+ (read s) (read s) (read s))) => 6
|
||
|
ind => 9
|
||
|
(with-input-from-string (s "Animal Crackers" :index j :start 6)
|
||
|
(read s)) => CRACKERS
|
||
|
</PRE>
|
||
|
</TT> The variable <TT>j</TT> is set to <TT>15</TT>. <P>
|
||
|
<P><B>Side Effects:</B><P>
|
||
|
<P>
|
||
|
The <A REL=DEFINITION HREF="26_glo_v.htm#value"><I>value</I></A> of the <A REL=DEFINITION HREF="26_glo_p.htm#place"><I>place</I></A> named by <I>index</I>, if any, is modified. <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_mk_s_1.htm#make-string-input-stream"><B>make-string-input-stream</B></A>, <A REL=CHILD HREF="03_f.htm">Section 3.6 (Traversal Rules and Side Effects)</A> <P>
|
||
|
<P><B>Notes:</B> None.
|
||
|
<P>
|
||
|
<P>
|
||
|
<P><HR>The following <A REL=META HREF="../Front/X3J13Iss.htm">X3J13 cleanup issues</A>, <I>not part of the specification</I>, apply to this section:<P><UL><LI> <A REL=CHILD HREF="../Issues/iss240.htm">MAPPING-DESTRUCTIVE-INTERACTION:EXPLICITLY-VAGUE</A><LI> <A REL=CHILD HREF="../Issues/iss362.htm">WITH-OPEN-FILE-SETQ:EXPLICITLY-VAGUE</A><LI> <A REL=CHILD HREF="../Issues/iss363.htm">WITH-OPEN-FILE-STREAM-EXTENT:DYNAMIC-EXTENT</A><LI> <A REL=CHILD HREF="../Issues/iss327.htm">STREAM-ACCESS:ADD-TYPES-ACCESSORS</A><LI> <A REL=CHILD HREF="../Issues/iss332.htm">SUBSEQ-OUT-OF-BOUNDS</A><LI> <A REL=CHILD HREF="../Issues/iss097.htm">DECLS-AND-DOC</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>
|