1
0
Fork 0
cl-sites/www.cs.cmu.edu/Groups/AI/html/cltl/clm/node183.html

159 lines
8.3 KiB
HTML
Raw Normal View History

2023-10-25 11:23:21 +02:00
<!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN">
<!Converted with LaTeX2HTML 0.6.5 (Tue Nov 15 1994) by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds >
<HEAD>
<TITLE>21.1. Standard Streams</TITLE>
</HEAD>
<BODY>
<meta name="description" value=" Standard Streams">
<meta name="keywords" value="clm">
<meta name="resource-type" value="document">
<meta name="distribution" value="global">
<P>
<b>Common Lisp the Language, 2nd Edition</b>
<BR> <HR><A NAME=tex2html3812 HREF="node184.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html3810 HREF="node182.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html3804 HREF="node182.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html3814 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html3815 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
<B> Next:</B> <A NAME=tex2html3813 HREF="node184.html"> Creating New Streams</A>
<B>Up:</B> <A NAME=tex2html3811 HREF="node182.html"> Streams</A>
<B> Previous:</B> <A NAME=tex2html3805 HREF="node182.html"> Streams</A>
<HR> <P>
<H1><A NAME=SECTION002510000000000000000>21.1. Standard Streams</A></H1>
<P>
There are several variables whose values are streams used by many
functions in the Lisp system. These variables and their uses are
listed here. By convention, variables that are expected to hold a
stream capable of input have names ending with <tt>-input</tt>, and
variables that are expected to hold a
stream capable of output have names ending with <tt>-output</tt>.
Variables expected to hold a
bidirectional stream have names ending with <tt>-io</tt>.
<P>
<BR><b>[Variable]</b><BR>
<tt>*standard-input*</tt><P>In the normal Lisp top-level loop, input is read from
<tt>*standard-input*</tt> (that is, whatever stream is the value of the global
variable <tt>*standard-input*</tt>). Many input functions, including
<tt>read</tt> and <tt>read-char</tt>, take a stream argument that defaults to
<tt>*standard-input*</tt>.
<P>
<BR><b>[Variable]</b><BR>
<tt>*standard-output*</tt><P>In the normal Lisp top-level loop, output is sent to
<tt>*standard-output*</tt> (that is, whatever stream is the value of the global
variable <tt>*standard-output*</tt>). Many output functions, including
<tt>print</tt> and <tt>write-char</tt>, take a stream argument that defaults
to <tt>*standard-output*</tt>.
<P>
<BR><b>[Variable]</b><BR>
<tt>*error-output*</tt><P>The value of <tt>*error-output*</tt> is a stream to which error messages
should be sent. Normally this is the same as <tt>*standard-output*</tt>,
but <tt>*standard-output*</tt> might be bound to a file and <tt>*error-output*</tt>
left going to the terminal or to a separate file of error messages.
<P>
<BR><b>[Variable]</b><BR>
<tt>*query-io*</tt><P>The value of <tt>*query-io*</tt> is a stream to be used when
asking questions of the user. The question should be output to this
stream, and the answer read from it. When
the normal input to a program may be coming from a file, questions such
as ``Do you really want to delete all of the files in your directory?'' should
nevertheless
be sent directly to the user; and the answer should come from the user,
not from the data file. For such purposes <tt>*query-io*</tt> should be
used instead of <tt>*standard-input*</tt> and <tt>*standard-output*</tt>.
<tt>*query-io*</tt> is used by such functions
as <tt>yes-or-no-p</tt>.
<P>
<BR><b>[Variable]</b><BR>
<tt>*debug-io*</tt><P>The value of <tt>*debug-io*</tt> is a stream to be used for interactive
debugging purposes. This is often the same as the value of <tt>*query-io*</tt>,
but need not be.
<P>
<BR><b>[Variable]</b><BR>
<tt>*terminal-io*</tt><P>The value of <tt>*terminal-io*</tt> is ordinarily
the stream that connects to the user's console.
Typically, writing to this stream would cause the output to appear
on a display screen, for example, and reading from the stream would
accept input from a keyboard.
<P>
It is intended
that standard input functions such as <tt>read</tt> and <tt>read-char</tt>,
when used with this stream, would cause ``echoing'' of the input
into the output side of the stream. (The means by which this is
accomplished are of course highly implementation-dependent.)
<P>
<BR><b>[Variable]</b><BR>
<tt>*trace-output*</tt><P>The value of <tt>*trace-output*</tt> is the stream on which the <tt>trace</tt>
function prints its output.
<P>
The variables
<tt>*standard-input*</tt>, <tt>*standard-output*</tt>,
<tt>*error-output*</tt>,
<tt>*trace-output*</tt>,
<tt>*query-io*</tt>, and <tt>*debug-io*</tt>
are initially bound to synonym streams that pass all
operations on to the stream that is the value of <tt>*terminal-io*</tt>.
(See <tt>make-synonym-stream</tt>.)
Thus any operations performed on those streams will go to the terminal.
<P>
<img align=bottom alt="change_begin" src="gif/change_begin.gif"><br>
X3J13 voted in January 1989
(STANDARD-INPUT-INITIAL-BINDING) <A NAME=19383>&#160;</A>
to replace the requirements of the preceding
paragraph with the following new requirements:
<P>
The seven standard stream variables,
<tt>*standard-input*</tt>, <tt>*standard-output*</tt>, <tt>*query-io*</tt>,
<tt>*debug-io*</tt>, <tt>*terminal-io*</tt>,
<tt>*error-output*</tt>, and
<tt>*trace-output*</tt>,
are initially bound to open streams. (These will be called
<i>the standard initial streams</i>.)
<P>
The streams that are the initial values of
<tt>*standard-input*</tt>, <tt>*query-io*</tt>, <tt>*debug-io*</tt>, and <tt>*terminal-io*</tt>
must support input.
<P>
The streams that are the initial values of
<tt>*standard-output*</tt>,
<tt>*error-output*</tt>,
<tt>*trace-output*</tt>, <tt>*query-io*</tt>, <tt>*debug-io*</tt>, and <tt>*terminal-io*</tt>
must support output.
<P>
None of the standard initial streams (including the one to which
<tt>*terminal-io*</tt> is initially bound) may be a synonym, either directly
or indirectly, for any of the standard stream variables
except <tt>*terminal-io*</tt>. For example, the initial value of
<tt>*trace-output*</tt> may be a synonym stream for <tt>*terminal-io*</tt>
but not a synonym stream for <tt>*standard-output*</tt> or <tt>*query-io*</tt>.
(These are examples of direct synonyms.) As another example,
<tt>*query-io*</tt> may be a two-way stream or echo stream whose
input component is a synonym for <tt>*terminal-io*</tt>,
but its input component may not be a synonym for <tt>*standard-input*</tt>
or <tt>*debug-io*</tt>. (These are examples of indirect synonyms.)
<P>
Any or all of the standard initial streams may be direct or indirect
synonyms for one or more common implementation-dependent streams.
For example, the standard initial streams might all be synonym streams
(or two-way or echo streams whose components are synonym streams)
to a pair of hidden terminal input and output streams maintained by
the implementation.
<P>
Part of the intent of these rules is to ensure that it is always safe
to bind any standard stream variable to the value of any other
standard stream variable (that is, unworkable circularities are
avoided) without unduly restricting implementation flexibility.
<br><img align=bottom alt="change_end" src="gif/change_end.gif">
<P>
No user program should ever change the value of <tt>*terminal-io*</tt>. A program
that wants (for example) to divert output to a file should do so by binding
the value of <tt>*standard-output*</tt>; that way error messages sent to
<tt>*error-output*</tt> can still get to the user by going through <tt>*terminal-io*</tt>,
which is usually what is desired.
<P>
<BR> <HR><A NAME=tex2html3812 HREF="node184.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html3810 HREF="node182.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html3804 HREF="node182.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html3814 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html3815 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
<B> Next:</B> <A NAME=tex2html3813 HREF="node184.html"> Creating New Streams</A>
<B>Up:</B> <A NAME=tex2html3811 HREF="node182.html"> Streams</A>
<B> Previous:</B> <A NAME=tex2html3805 HREF="node182.html"> Streams</A>
<HR> <P>
<HR>
<P><ADDRESS>
AI.Repository@cs.cmu.edu
</ADDRESS>
</BODY>