1
0
Fork 0
cl-sites/novaspec.org/cl/f_with-open-stream.html
2025-02-05 18:52:26 +01:00

302 lines
No EOL
5.9 KiB
HTML

<!DOCTYPE HTML>
<HTML LANG="en-us"
><HEAD
><TITLE
>with-open-stream | Common Lisp Nova Spec</TITLE
><META CHARSET="US-ASCII"
><LINK REL="canonical" HREF="f_with-open-stream.html"
><LINK REL="next" HREF="f_listen.html" TYPE="text/html" TITLE="listen"
><LINK REL="prev" HREF="f_close.html" TYPE="text/html" TITLE="close"
><LINK REL="up" HREF="21_2_Streams_Dictionary.html" TYPE="text/html" TITLE="21.2 Streams 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"
>&#8594; <A HREF="21_Streams.html"
>21. Streams</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="21_2_Streams_Dictionary.html"
>21.2 Streams Dictionary</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="f_with-open-stream.html"
>with-open-stream</A
></SPAN
></DIV
><DIV CLASS="apropos"
><DIV CLASS="apropos-io"
><A HREF="f_close.html" CLASS="prev"
>&#8592;</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_listen.html" CLASS="next"
>&#8594;</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="with-open-stream"
></SPAN
><B
>with-open-stream</B
></TD
><TD ALIGN="RIGHT" VALIGN="BASELINE" WIDTH="0" NOWRAP="NOWRAP" CLASS="ftype"
><I
>Macro</I
></TD
></TR
></TABLE
><HR
></DIV
><UL CLASS="subtoc"
></UL
><DL
><DT
><B
>Syntax</B
></DT
><DD
><DIV CLASS="DefmacWithValuesNewline"
><DIV
><B
>with-open-stream</B
> <SPAN CLASS="cmr"
>(</SPAN
><SPAN CLASS="cmssi"
>var</SPAN
> <SPAN CLASS="cmssi"
>stream</SPAN
><SPAN CLASS="cmr"
>)</SPAN
> <SPAN CLASS="cmsy"
>{</SPAN
><VAR CLASS="param"
>declaration</VAR
><SPAN CLASS="cmsy"
>}</SPAN
><SPAN CLASS="cmr"
>*</SPAN
> <SPAN CLASS="cmsy"
>{</SPAN
><VAR CLASS="param"
>form</VAR
><SPAN CLASS="cmsy"
>}</SPAN
><SPAN CLASS="cmr"
>*</SPAN
> </DIV
><DIV
><SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> <SPAN CLASS="cmsy"
>{</SPAN
><VAR CLASS="param"
>result</VAR
><SPAN CLASS="cmsy"
>}</SPAN
><SPAN CLASS="cmr"
>*</SPAN
></DIV
></DIV
></DD
><DT
><B
>Arguments and Values</B
></DT
><DD
><P CLASS="j"
><VAR CLASS="param"
>var</VAR
> &#8212; a <A HREF="26_1_Glossary.html#variable"
><EM CLASS="term"
>variable</EM
></A
> <A HREF="26_1_Glossary.html#name"
><EM CLASS="term"
>name</EM
></A
>. </P
><P CLASS="j"
><VAR CLASS="param"
>stream</VAR
> &#8212; a <A HREF="26_1_Glossary.html#form"
><EM CLASS="term"
>form</EM
></A
>; evaluated to produce a <A HREF="26_1_Glossary.html#stream"
><EM CLASS="term"
>stream</EM
></A
>. </P
><P CLASS="j"
><VAR CLASS="param"
>declaration</VAR
> &#8212; a <A HREF="m_declare.html" CLASS="misc"
><B
>declare</B
></A
> <A HREF="26_1_Glossary.html#expression"
><EM CLASS="term"
>expression</EM
></A
>; not evaluated. </P
><P CLASS="j"
><VAR CLASS="param"
>forms</VAR
> &#8212; an <A HREF="26_1_Glossary.html#implicit_progn"
><EM CLASS="term"
>implicit progn</EM
></A
>. </P
><P CLASS="j"
><VAR CLASS="param"
>results</VAR
> &#8212; the <A HREF="26_1_Glossary.html#value"
><EM CLASS="term"
>values</EM
></A
> returned by the <VAR CLASS="param"
>forms</VAR
>.</P
></DD
><DT
><B
>Description</B
></DT
><DD
><P CLASS="j"
><A HREF="f_with-open-stream.html" CLASS="macref"
><B
>with-open-stream</B
></A
> performs a series of operations on <VAR CLASS="param"
>stream</VAR
>, returns a value, and then closes the <VAR CLASS="param"
>stream</VAR
>. </P
><P CLASS="j"
><VAR CLASS="param"
>Var</VAR
> is bound to the value of <VAR CLASS="param"
>stream</VAR
>, and then <VAR CLASS="param"
>forms</VAR
> are executed as an <A HREF="26_1_Glossary.html#implicit_progn"
><EM CLASS="term"
>implicit progn</EM
></A
>. <VAR CLASS="param"
>stream</VAR
> is automatically closed on exit from <A HREF="f_with-open-stream.html" CLASS="macref"
><B
>with-open-stream</B
></A
>, no matter whether the exit is normal or abnormal. The <VAR CLASS="param"
>stream</VAR
> has <A HREF="26_1_Glossary.html#dynamic_extent"
><EM CLASS="term"
>dynamic extent</EM
></A
>; its <A HREF="26_1_Glossary.html#extent"
><EM CLASS="term"
>extent</EM
></A
> ends when the <A HREF="26_1_Glossary.html#form"
><EM CLASS="term"
>form</EM
></A
> is exited. </P
><P CLASS="j"
>The consequences are undefined if an attempt is made to <A HREF="26_1_Glossary.html#assign"
><EM CLASS="term"
>assign</EM
></A
> the the <A HREF="26_1_Glossary.html#variable"
><EM CLASS="term"
>variable</EM
></A
> <VAR CLASS="param"
>var</VAR
> with the <VAR CLASS="param"
>forms</VAR
>.</P
></DD
><DT
><B
>Examples</B
></DT
><DD
><PRE CLASS="screen"
>(with-open-stream (s (make-string-input-stream "1 2 3 4"))
(+ (read s) (read s) (read s))) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 6</PRE
></DD
><DT
><B
>Side Effects</B
></DT
><DD
><P CLASS="j"
>The <VAR CLASS="param"
>stream</VAR
> is closed (upon exit).</P
></DD
><DT
><B
>See Also</B
></DT
><DD
><P CLASS="j"
><A HREF="f_close.html" CLASS="funref"
><B
>close</B
></A
></P
></DD
></DL
></DIV
></DIV
><DIV CLASS="footer"
><DIV CLASS="btmnav"
><A HREF="f_close.html" CLASS="prev"
>&#8592;</A
><A HREF="f_listen.html" CLASS="next"
>&#8594;</A
></DIV
><DIV CLASS="trail"
>Conversion to HTML copyright 2023 by Gilbert Baumann</DIV
></DIV
></DIV
><SCRIPT
>domReady();</SCRIPT
></BODY
></HTML
>