| 1 |
<?xml version="1.0" encoding="utf-8"?> |
| 2 |
<!DOCTYPE book [ |
| 3 |
<!ENTITY % eclent SYSTEM "ecl.ent"> |
| 4 |
%eclent; |
| 5 |
]> |
| 6 |
<book xmlns="http://docbook.org/ns/docbook" version="5.0" xml:lang="en"> |
| 7 |
<chapter xml:id="Input-and-output"> |
| 8 |
<title>Input and Output</title> |
| 9 |
<section xml:id="Read-macros"> |
| 10 |
<title>Read macros</title> |
| 11 |
<variablelist> |
| 12 |
<varlistentry> |
| 13 |
<term>#P"</term> |
| 14 |
<listitem> |
| 15 |
<para><literal>#"<replaceable>string</replaceable>"</literal> reads a pathname. <literal>#"<replaceable>string</replaceable>"</literal> is equivalent |
| 16 |
to <literal>(pathname "<replaceable>string</replaceable>")</literal>.</para> |
| 17 |
</listitem> |
| 18 |
</varlistentry> |
| 19 |
<varlistentry> |
| 20 |
<term>#$</term> |
| 21 |
<listitem> |
| 22 |
<para><literal>#$<replaceable>integer</replaceable></literal> reads a random state. <literal>#$</literal><replaceable>integer</replaceable> is |
| 23 |
equivalent to <literal>(make-random-state <replaceable>integer</replaceable>)</literal>.</para> |
| 24 |
</listitem> |
| 25 |
</varlistentry> |
| 26 |
</variablelist> |
| 27 |
<para>The <literal>#</literal> macro '<literal>#,</literal>' works as described in &Steele84;, only |
| 28 |
if it is included in a constant object. The forms immediately after |
| 29 |
<literal>`#,'</literal> below will be evaluated when the compiled code is loaded.</para> |
| 30 |
<screen> |
| 31 |
'#,x |
| 32 |
'(a b c (d #,e f) g) |
| 33 |
#(1 2 3 #,(+ a b c) 5 6) |
| 34 |
#C(0.0 #,(exp 1)) |
| 35 |
</screen> |
| 36 |
<para>Otherwise, the effect of using '<literal>#,</literal>' is unpredictable. Note that, when |
| 37 |
interpreted code is loaded, '<literal>#,</literal>' has the same effect as the <literal>#</literal> |
| 38 |
macro '<literal>#.</literal>'.</para> |
| 39 |
</section> |
| 40 |
|
| 41 |
<section xml:id="Input-Output-functions"> |
| 42 |
<title>Input and Output Functions</title> |
| 43 |
<para>The input and output functions of &ECL; almost follow the definitions in |
| 44 |
Chapter 22 of &Steele84;. Most of the differences come from the fact |
| 45 |
that, in &ECL;, input from the terminal is always in line mode and binary I/O |
| 46 |
is not supported.</para> |
| 47 |
<para>In &ECL;, <literal>*terminal-io*</literal> is a two-way stream from the standard input |
| 48 |
and to the standard output. The echoing to the terminal is performed by the |
| 49 |
underlying operating system. In particular, when a disk file is assigned to |
| 50 |
the standard output, nothing will be echoed at the terminal.</para> |
| 51 |
<para>Those functions that deviate from the definitions in &Steele84; are |
| 52 |
listed below.</para> |
| 53 |
<blockquote> |
| 54 |
<screen><indexterm role="fn"><primary>load</primary></indexterm>— Function: <function>load</function> <varname>pathname &key :print :verbose :if-does-not-exist</varname></screen> |
| 55 |
<para>If <replaceable>pathname</replaceable> does not specify the filetype of the input file, then load |
| 56 |
uses the association list <replaceable>si::*load-search-list*</replaceable> to find out a suitable |
| 57 |
filetype and the function to load it. Typically, this search list is made of |
| 58 |
the elements <literal>.fas</literal>, <literal>.lsp</literal> and <literal>.lisp</literal>, in this order. If |
| 59 |
everything fails, a file without filetype will be loaded.</para> |
| 60 |
</blockquote> |
| 61 |
<blockquote> |
| 62 |
<screen><indexterm role="fn"><primary>open</primary></indexterm>— Function: <function>open</function> <varname></varname></screen> |
| 63 |
<para>Streams can only have element type <literal>base-char</literal>, <literal>(signed-byte 8)</literal> |
| 64 |
and <literal>(unsigned-byte 8)</literal>. The <literal>:external-format</literal> is always <literal>:default</literal>.</para> |
| 65 |
</blockquote> |
| 66 |
<blockquote> |
| 67 |
<screen><indexterm role="fn"><primary>close</primary></indexterm>— Function: <function>close</function> <varname></varname></screen> |
| 68 |
<para>The keyword variable <replaceable>:abort</replaceable> is always ignored.</para> |
| 69 |
</blockquote> |
| 70 |
<blockquote> |
| 71 |
<screen><indexterm role="fn"><primary>listen</primary></indexterm>— Function: <function>listen</function> <varname></varname></screen> |
| 72 |
<para>This routine requires some low level functions which are not available on |
| 73 |
all platforms (For instance on <literal>Windows</literal>). When ECL is not able to |
| 74 |
determine whether a stream is interactive, <literal>listen</literal> returns true unless |
| 75 |
an end of file has been previously detected.</para> |
| 76 |
</blockquote> |
| 77 |
<blockquote> |
| 78 |
<screen><indexterm role="fn"><primary>clear-input</primary></indexterm>— Function: <function>clear-input</function> <varname></varname></screen> |
| 79 |
<para>The functions <literal>clear-input</literal> and <literal>clear-output</literal> do nothing.</para> |
| 80 |
</blockquote> |
| 81 |
<blockquote> |
| 82 |
<screen><indexterm role="fn"><primary>read-char-no-hang</primary></indexterm>— Function: <function>read-char-no-hang</function> <varname></varname></screen> |
| 83 |
<para><literal>read-char-no-hang</literal> is equivalent to <literal>read-char</literal>.</para> |
| 84 |
</blockquote> |
| 85 |
<para>The functions <literal>princ</literal>, <literal>write-char</literal> and <literal>write-byte</literal> do not |
| 86 |
always flush the stream. The stream is flushed when</para> |
| 87 |
<orderedlist numeration="arabic"> |
| 88 |
<listitem> |
| 89 |
<para>a newline character is written, or</para> |
| 90 |
</listitem> |
| 91 |
<listitem> |
| 92 |
<para>the input from the terminal is requested in the case that these |
| 93 |
functions operate on <literal>*terminal-io*</literal></para> |
| 94 |
</listitem> |
| 95 |
</orderedlist> |
| 96 |
</section> |
| 97 |
|
| 98 |
<section xml:id="Network-streams"> |
| 99 |
<title>Network Streams</title> |
| 100 |
<para>With a configuration option, the following function is available which opens |
| 101 |
streams across network connections.</para> |
| 102 |
<blockquote> |
| 103 |
<screen><indexterm role="fn"><primary>open-client-stream</primary></indexterm>— Function: <function>open-client-stream</function> <varname>host port</varname></screen> |
| 104 |
<para>The string <replaceable>host</replaceable> indicates the name of the host, while <replaceable>port</replaceable> is an |
| 105 |
integer which identifies the port number to which to connect. This function |
| 106 |
returns a two-way stream which can be used in any of the stream operations.</para> |
| 107 |
</blockquote> |
| 108 |
<blockquote> |
| 109 |
<screen><indexterm role="fn"><primary>open-server-stream</primary></indexterm>— Function: <function>open-server-stream</function> <varname>host port</varname></screen> |
| 110 |
<para>A stream connected to port number <replaceable>port</replaceable> is created to which clients can |
| 111 |
connect. This function returns a two-way stream which can be used in any of |
| 112 |
the stream operations.</para> |
| 113 |
</blockquote> |
| 114 |
</section> |
| 115 |
|
| 116 |
<section xml:id="CLOS-streams"> |
| 117 |
<title>CLOS Streams</title> |
| 118 |
<para>When the optional CLOS subsystem is available, an interface is provided by |
| 119 |
&ECL; for using CLOS objects as Common-Lisp input/output character streams. |
| 120 |
Such support can be used for instance to build interactive character streams, |
| 121 |
which may be used by applications as the stream argument for Common-Lisp I/O |
| 122 |
functions such as <literal>read</literal>, <literal>listen</literal>, <literal>prin1</literal>, etc. The |
| 123 |
fundamental interface to <literal>clos-stream</literal> objects consists of |
| 124 |
(generic) functions which implement the basic Common-Lisp character stream |
| 125 |
operations (see Common-Lisp, Chapter 22) but whose details are implementation |
| 126 |
dependent.</para> |
| 127 |
<para>The following functions are automatically invoked by &ECL; when a stream |
| 128 |
operation involves a CLOS object as a stream parameter. The programmer should |
| 129 |
define these methods for any class of objects which are to be used for |
| 130 |
character input/output.</para> |
| 131 |
|
| 132 |
<section xml:id="CLOS-Stream-Input"> |
| 133 |
<title>CLOS Stream Input</title> |
| 134 |
<para>Character input from an <literal>clos-stream</literal> is implemented by the |
| 135 |
following methods.</para> |
| 136 |
<blockquote> |
| 137 |
<screen><indexterm role="fn"><primary>stream-read-char</primary></indexterm>— Method: <function>stream-read-char</function> (<varname>object</varname> <varname>clos-stream</varname>)</screen> |
| 138 |
<para>Returns the next character object read from the CLOS stream <replaceable>object</replaceable>.</para> |
| 139 |
</blockquote> |
| 140 |
<blockquote> |
| 141 |
<screen><indexterm role="fn"><primary>stream-unread-char</primary></indexterm>— Method: <function>stream-unread-char</function> (<varname>object</varname> <varname>clos-stream</varname>) <varname>character</varname></screen> |
| 142 |
<para>Unreads the character object <replaceable>character</replaceable> from the CLOS stream <replaceable>object</replaceable>. |
| 143 |
<replaceable>character</replaceable> will be the next character read by <literal>stream-read-char</literal>.</para> |
| 144 |
</blockquote> |
| 145 |
<blockquote> |
| 146 |
<screen><indexterm role="fn"><primary>stream-listen</primary></indexterm>— Method: <function>stream-listen</function> (<varname>object</varname> <varname>clos-stream</varname>)</screen> |
| 147 |
<para>Returns () is no character is immediately available from the CLOS stream |
| 148 |
<replaceable>object</replaceable>. Otherwise, the next character is returned, as if |
| 149 |
<literal>stream-peek-char</literal> had been called.</para> |
| 150 |
</blockquote> |
| 151 |
<blockquote> |
| 152 |
<screen><indexterm role="fn"><primary>stream-clear-input</primary></indexterm>— Method: <function>stream-clear-input</function> <varname>object</varname></screen> |
| 153 |
<para>Clears any buffered characters on the CLOS stream <replaceable>object</replaceable>. Returns ().</para> |
| 154 |
</blockquote> |
| 155 |
</section> |
| 156 |
|
| 157 |
<section xml:id="CLOS-Stream-Output"> |
| 158 |
<title>CLOS Stream Output</title> |
| 159 |
<para>Character output from an <literal>clos-stream</literal> is implemented by the |
| 160 |
following methods.</para> |
| 161 |
<blockquote> |
| 162 |
<screen><indexterm role="fn"><primary>stream-write-char</primary></indexterm>— Method: <function>stream-write-char</function> (<varname>object</varname> <varname>clos-stream</varname>) <varname>character</varname></screen> |
| 163 |
<para>Outputs the character <replaceable>character</replaceable> to the CLOS stream <replaceable>object</replaceable> and |
| 164 |
returns it.</para> |
| 165 |
</blockquote> |
| 166 |
<blockquote> |
| 167 |
<screen><indexterm role="fn"><primary>stream-clear-output</primary></indexterm>— Method: <function>stream-clear-output</function> (<varname>object</varname> <varname>clos-stream</varname>)</screen> |
| 168 |
<para>Aborts any outstanding output operation on the CLOS stream <replaceable>object</replaceable> and |
| 169 |
returns ().</para> |
| 170 |
</blockquote> |
| 171 |
<blockquote> |
| 172 |
<screen><indexterm role="fn"><primary>stream-force-output</primary></indexterm>— Method: <function>stream-force-output</function> (<varname>object</varname> <varname>clos-stream</varname>)</screen> |
| 173 |
<para>Initiates the emptying of the internal buffers on the CLOS stream <replaceable>object</replaceable> |
| 174 |
and returns ().</para> |
| 175 |
</blockquote> |
| 176 |
</section> |
| 177 |
|
| 178 |
<section xml:id="CLOS-Stream-common"> |
| 179 |
<title>CLOS Stream common</title> |
| 180 |
<para>The following functions should be available for all CLOS streams.</para> |
| 181 |
<blockquote> |
| 182 |
<screen><indexterm role="fn"><primary>stream-interactive-p</primary></indexterm>— Method: <function>stream-interactive-p</function> (<varname>object</varname> <varname>clos-stream</varname>)</screen> |
| 183 |
</blockquote> |
| 184 |
<blockquote> |
| 185 |
<screen><indexterm role="fn"><primary>stream-close</primary></indexterm>— Method: <function>stream-close</function> (<varname>object</varname> <varname>clos-stream</varname>)</screen> |
| 186 |
<para>Closes the stream for any further input or output.</para> |
| 187 |
</blockquote> |
| 188 |
</section> |
| 189 |
</section> |
| 190 |
</chapter> |
| 191 |
<!-- Keep this comment at the end of the file |
| 192 |
Local variables: |
| 193 |
sgml-parent-document: "ecl.xml" |
| 194 |
sgml-indent-step: 1 |
| 195 |
nxml-child-indent: 1 |
| 196 |
nxml-outline-child-indent:1 |
| 197 |
fill-column: 79 |
| 198 |
End: |
| 199 |
--></book> |