~rdoering/ubuntu/karmic/erlang/fix-535090

« back to all changes in this revision

Viewing changes to lib/stdlib/doc/src/io_lib.xml

  • Committer: Bazaar Package Importer
  • Author(s): Sergei Golovan
  • Date: 2009-02-15 16:42:52 UTC
  • mfrom: (3.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090215164252-q5x4rcf8a5pbesb1
Tags: 1:12.b.5-dfsg-2
Upload to unstable after lenny is released.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0" encoding="latin1" ?>
 
2
<!DOCTYPE erlref SYSTEM "erlref.dtd">
 
3
 
 
4
<erlref>
 
5
  <header>
 
6
    <copyright>
 
7
      <year>1996</year>
 
8
      <year>2007</year>
 
9
      <holder>Ericsson AB, All Rights Reserved</holder>
 
10
    </copyright>
 
11
    <legalnotice>
 
12
  The contents of this file are subject to the Erlang Public License,
 
13
  Version 1.1, (the "License"); you may not use this file except in
 
14
  compliance with the License. You should have received a copy of the
 
15
  Erlang Public License along with this software. If not, it can be
 
16
  retrieved online at http://www.erlang.org/.
 
17
 
 
18
  Software distributed under the License is distributed on an "AS IS"
 
19
  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 
20
  the License for the specific language governing rights and limitations
 
21
  under the License.
 
22
 
 
23
  The Initial Developer of the Original Code is Ericsson AB.
 
24
    </legalnotice>
 
25
 
 
26
    <title>io_lib</title>
 
27
    <prepared></prepared>
 
28
    <docno></docno>
 
29
    <date></date>
 
30
    <rev></rev>
 
31
  </header>
 
32
  <module>io_lib</module>
 
33
  <modulesummary>IO Library Functions</modulesummary>
 
34
  <description>
 
35
    <p>This module contains functions for converting to and from
 
36
      strings (lists of characters). They are used for implementing the
 
37
      functions in the <c>io</c> module. There is no guarantee that the
 
38
      character lists returned from some of the functions are flat,
 
39
      they can be deep lists. <c>lists:flatten/1</c> can be used for
 
40
      flattening deep lists.</p>
 
41
  </description>
 
42
 
 
43
  <section>
 
44
    <title>DATA TYPES</title>
 
45
    <code type="none">
 
46
chars() = [char() | chars()]</code>
 
47
  </section>
 
48
  <funcs>
 
49
    <func>
 
50
      <name>nl() -> chars()</name>
 
51
      <fsummary>Write a newline</fsummary>
 
52
      <desc>
 
53
        <p>Returns a character list which represents a new line
 
54
          character.</p>
 
55
      </desc>
 
56
    </func>
 
57
    <func>
 
58
      <name>write(Term) -></name>
 
59
      <name>write(Term, Depth) -> chars()</name>
 
60
      <fsummary>Write a term</fsummary>
 
61
      <type>
 
62
        <v>Term = term()</v>
 
63
        <v>Depth = int()</v>
 
64
      </type>
 
65
      <desc>
 
66
        <p>Returns a character list which represents <c>Term</c>. The
 
67
          <c>Depth</c> (-1) argument controls the depth of the
 
68
          structures written. When the specified depth is reached,
 
69
          everything below this level is replaced by "...". For
 
70
          example:</p>
 
71
        <pre>
 
72
1> <input>lists:flatten(io_lib:write({1,[2],[3],[4,5],6,7,8,9})).</input>
 
73
"{1,[2],[3],[4,5],6,7,8,9}"
 
74
2> <input>lists:flatten(io_lib:write({1,[2],[3],[4,5],6,7,8,9}, 5)).</input>
 
75
"{1,[2],[3],[...],...}"</pre>
 
76
      </desc>
 
77
    </func>
 
78
    <func>
 
79
      <name>print(Term) -></name>
 
80
      <name>print(Term, Column, LineLength, Depth) -> chars()</name>
 
81
      <fsummary>Pretty print a term</fsummary>
 
82
      <type>
 
83
        <v>Term = term()</v>
 
84
        <v>Column = LineLenght = Depth = int()</v>
 
85
      </type>
 
86
      <desc>
 
87
        <p>Also returns a list of characters which represents
 
88
          <c>Term</c>, but breaks representations which are longer than
 
89
          one line into many lines and indents each line sensibly. It
 
90
          also tries to detect and output lists of printable characters 
 
91
          as strings. <c>Column</c> is the starting column (1),
 
92
          <c>LineLength</c> the maximum line length (80), and
 
93
          <c>Depth</c> (-1) the maximum print depth.</p>
 
94
      </desc>
 
95
    </func>
 
96
    <func>
 
97
      <name>fwrite(Format, Data) -></name>
 
98
      <name>format(Format, Data) -> chars()</name>
 
99
      <fsummary>Write formatted output</fsummary>
 
100
      <type>
 
101
        <v>Format = atom() | string() | binary()</v>
 
102
        <v>Data = [term()]</v>
 
103
      </type>
 
104
      <desc>
 
105
        <p>Returns a character list which represents <c>Data</c>
 
106
          formatted in accordance with <c>Format</c>. See
 
107
          <seealso marker="io#fwrite/1">io:fwrite/1,2,3</seealso> for a detailed
 
108
          description of the available formatting options. A fault is
 
109
          generated if there is an error in the format string or
 
110
          argument list.</p>
 
111
      </desc>
 
112
    </func>
 
113
    <func>
 
114
      <name>fread(Format, String) -> Result</name>
 
115
      <fsummary>Read formatted input</fsummary>
 
116
      <type>
 
117
        <v>Format = String = string()</v>
 
118
        <v>Result = {ok, InputList, LeftOverChars} | {more, RestFormat, Nchars, InputStack} | {error, What}</v>
 
119
        <v>&nbsp;InputList = chars()</v>
 
120
        <v>&nbsp;LeftOverChars = string()</v>
 
121
        <v>&nbsp;RestFormat = string()</v>
 
122
        <v>&nbsp;Nchars = int()</v>
 
123
        <v>&nbsp;InputStack = chars()</v>
 
124
        <v>&nbsp;What = term()</v>
 
125
      </type>
 
126
      <desc>
 
127
        <p>Tries to read <c>String</c> in accordance with the control
 
128
          sequences in <c>Format</c>. See
 
129
          <seealso marker="io#fread/3">io:fread/3</seealso> for a detailed
 
130
          description of the available formatting options. It is
 
131
          assumed that <c>String</c> contains whole lines. It returns:</p>
 
132
        <taglist>
 
133
          <tag><c>{ok, InputList, LeftOverChars}</c></tag>
 
134
          <item>
 
135
            <p>The string was read. <c>InputList</c> is the list of
 
136
              successfully matched and read items, and
 
137
              <c>LeftOverChars</c> are the input characters not used.</p>
 
138
          </item>
 
139
          <tag><c>{more, RestFormat, Nchars, InputStack}</c></tag>
 
140
          <item>
 
141
            <p>The string was read, but more input is needed in order
 
142
              to complete the original format string. <c>RestFormat</c>
 
143
              is the remaining format string, <c>NChars</c> the number
 
144
              of characters scanned, and <c>InputStack</c> is the
 
145
              reversed list of inputs matched up to that point.</p>
 
146
          </item>
 
147
          <tag><c>{error, What}</c></tag>
 
148
          <item>
 
149
            <p>The read operation failed and the parameter <c>What</c>
 
150
              gives a hint about the error.</p>
 
151
          </item>
 
152
        </taglist>
 
153
        <p>Example:</p>
 
154
        <pre>
 
155
3> <input>io_lib:fread("~f~f~f", "15.6 17.3e-6 24.5").</input>
 
156
{ok,[15.6,1.73e-5,24.5],[]}</pre>
 
157
      </desc>
 
158
    </func>
 
159
    <func>
 
160
      <name>fread(Continuation, String, Format) -> Return</name>
 
161
      <fsummary>Re-entrant formatted reader</fsummary>
 
162
      <type>
 
163
        <v>Continuation = see below</v>
 
164
        <v>String = Format = string()</v>
 
165
        <v>Return = {done, Result, LeftOverChars} | {more, Continuation}</v>
 
166
        <v>&nbsp;Result = {ok, InputList} | eof | {error, What}</v>
 
167
        <v>&nbsp;&nbsp;InputList = chars()</v>
 
168
        <v>&nbsp;&nbsp;What = term()()</v>
 
169
        <v>&nbsp;LeftOverChars = string()</v>
 
170
      </type>
 
171
      <desc>
 
172
        <p>This is the re-entrant formatted reader. The continuation of
 
173
          the first call to the functions must be <c>[]</c>. Refer to
 
174
          Armstrong, Virding, Williams, 'Concurrent Programming in
 
175
          Erlang', Chapter 13 for a complete description of how the
 
176
          re-entrant input scheme works.</p>
 
177
        <p>The function returns:</p>
 
178
        <taglist>
 
179
          <tag><c>{done, Result, LeftOverChars}</c></tag>
 
180
          <item>
 
181
            <p>The input is complete. The result is one of the
 
182
              following:</p>
 
183
            <taglist>
 
184
              <tag><c>{ok, InputList}</c></tag>
 
185
              <item>
 
186
                <p>The string was read. <c>InputList</c> is the list of
 
187
                  successfully matched and read items, and
 
188
                  <c>LeftOverChars</c> are the remaining characters.</p>
 
189
              </item>
 
190
              <tag><c>eof</c></tag>
 
191
              <item>
 
192
                <p>End of file has been encountered.
 
193
                  <c>LeftOverChars</c> are the input characters not
 
194
                  used.</p>
 
195
              </item>
 
196
              <tag><c>{error, What}</c></tag>
 
197
              <item>
 
198
                <p>An error occurred and the parameter <c>What</c> gives
 
199
                  a hint about the error.</p>
 
200
              </item>
 
201
            </taglist>
 
202
          </item>
 
203
          <tag><c>{more, Continuation}</c></tag>
 
204
          <item>
 
205
            <p>More data is required to build a term.
 
206
              <c>Continuation</c> must be passed to <c>fread/3</c>,
 
207
              when more data becomes available.</p>
 
208
          </item>
 
209
        </taglist>
 
210
      </desc>
 
211
    </func>
 
212
    <func>
 
213
      <name>write_atom(Atom) -> chars()</name>
 
214
      <fsummary>Write an atom</fsummary>
 
215
      <type>
 
216
        <v>Atom = atom()</v>
 
217
      </type>
 
218
      <desc>
 
219
        <p>Returns the list of characters needed to print the atom
 
220
          <c>Atom</c>.</p>
 
221
      </desc>
 
222
    </func>
 
223
    <func>
 
224
      <name>write_string(String) -> chars()</name>
 
225
      <fsummary>Write a string</fsummary>
 
226
      <type>
 
227
        <v>String = string()</v>
 
228
      </type>
 
229
      <desc>
 
230
        <p>Returns the list of characters needed to print <c>String</c>
 
231
          as a string.</p>
 
232
      </desc>
 
233
    </func>
 
234
    <func>
 
235
      <name>write_char(Integer) -> chars()</name>
 
236
      <fsummary>Write a character</fsummary>
 
237
      <type>
 
238
        <v>Integer = int()</v>
 
239
      </type>
 
240
      <desc>
 
241
        <p>Returns the list of characters needed to print a character
 
242
          constant.</p>
 
243
      </desc>
 
244
    </func>
 
245
    <func>
 
246
      <name>indentation(String, StartIndent) -> int()</name>
 
247
      <fsummary>Indentation after printing string</fsummary>
 
248
      <type>
 
249
        <v>String = string()</v>
 
250
        <v>StartIndent = int()</v>
 
251
      </type>
 
252
      <desc>
 
253
        <p>Returns the indentation if <c>String</c> has been printed,
 
254
          starting at <c>StartIndent</c>.</p>
 
255
      </desc>
 
256
    </func>
 
257
    <func>
 
258
      <name>char_list(Term) -> bool()</name>
 
259
      <fsummary>Test for a list of characters</fsummary>
 
260
      <type>
 
261
        <v>Term = term()</v>
 
262
      </type>
 
263
      <desc>
 
264
        <p>Returns <c>true</c> if <c>Term</c> is a flat list of
 
265
          characters, otherwise it returns <c>false</c>.</p>
 
266
      </desc>
 
267
    </func>
 
268
    <func>
 
269
      <name>deep_char_list(Term) -> bool()</name>
 
270
      <fsummary>Test for a deep list of characters</fsummary>
 
271
      <type>
 
272
        <v>Term = term()</v>
 
273
      </type>
 
274
      <desc>
 
275
        <p>Returns <c>true</c> if <c>Term</c> is a, possibly deep, list
 
276
          of characters, otherwise it returns <c>false</c>.</p>
 
277
      </desc>
 
278
    </func>
 
279
    <func>
 
280
      <name>printable_list(Term) -> bool()</name>
 
281
      <fsummary>Test for a list of printable characters</fsummary>
 
282
      <type>
 
283
        <v>Term = term()</v>
 
284
      </type>
 
285
      <desc>
 
286
        <p>Returns <c>true</c> if <c>Term</c> is a flat list of
 
287
          printable characters, otherwise it returns <c>false</c>.</p>
 
288
      </desc>
 
289
    </func>
 
290
  </funcs>
 
291
</erlref>
 
292