File: io_lib.3

package info (click to toggle)
erlang-manpages 1%3A12.b.3-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 4,188 kB
  • ctags: 2
  • sloc: makefile: 68; perl: 30; sh: 15
file content (293 lines) | stat: -rw-r--r-- 6,211 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
.TH io_lib 3 "stdlib  1.15.3" "Ericsson AB" "ERLANG MODULE DEFINITION"
.SH MODULE
io_lib \- IO Library Functions
.SH DESCRIPTION
.LP
This module contains functions for converting to and from strings (lists of characters)\&. They are used for implementing the functions in the \fIio\fR module\&. There is no guarantee that the character lists returned from some of the functions are flat, they can be deep lists\&. \fIlists:flatten/1\fR can be used for flattening deep lists\&.

.SH DATA TYPES

.nf
chars() = [char() | chars()]
.fi
.SH EXPORTS
.LP
.B
nl() -> chars()
.br
.RS
.LP
Returns a character list which represents a new line character\&.
.RE
.LP
.B
write(Term) ->
.br
.B
write(Term, Depth) -> chars()
.br
.RS
.TP
Types
Term = term()
.br
Depth = int()
.br
.RE
.RS
.LP
Returns a character list which represents \fITerm\fR\&. The \fIDepth\fR (-1) argument controls the depth of the structures written\&. When the specified depth is reached, everything below this level is replaced by "\&.\&.\&."\&. For example:

.nf
1> lists:flatten(io_lib:write({1,[2],[3],[4,5],6,7,8,9}))\&.

"{1,[2],[3],[4,5],6,7,8,9}"
2> lists:flatten(io_lib:write({1,[2],[3],[4,5],6,7,8,9}, 5))\&.

"{1,[2],[3],[\&.\&.\&.],\&.\&.\&.}"
.fi
.RE
.LP
.B
print(Term) ->
.br
.B
print(Term, Column, LineLength, Depth) -> chars()
.br
.RS
.TP
Types
Term = term()
.br
Column = LineLenght = Depth = int()
.br
.RE
.RS
.LP
Also returns a list of characters which represents \fITerm\fR, but breaks representations which are longer than one line into many lines and indents each line sensibly\&. It also tries to detect and output lists of printable characters as strings\&. \fIColumn\fR is the starting column (1), \fILineLength\fR the maximum line length (80), and \fIDepth\fR (-1) the maximum print depth\&.
.RE
.LP
.B
fwrite(Format, Data) ->
.br
.B
format(Format, Data) -> chars()
.br
.RS
.TP
Types
Format = atom() | string() | binary()
.br
Data = [term()]
.br
.RE
.RS
.LP
Returns a character list which represents \fIData\fR formatted in accordance with \fIFormat\fR\&. See io:fwrite/1,2,3 for a detailed description of the available formatting options\&. A fault is generated if there is an error in the format string or argument list\&.
.RE
.LP
.B
fread(Format, String) -> Result
.br
.RS
.TP
Types
Format = String = string()
.br
Result = {ok, InputList, LeftOverChars} | {more, RestFormat, Nchars, InputStack} | {error, What}
.br
InputList = chars()
.br
LeftOverChars = string()
.br
RestFormat = string()
.br
Nchars = int()
.br
InputStack = chars()
.br
What = term()
.br
.RE
.RS
.LP
Tries to read \fIString\fR in accordance with the control sequences in \fIFormat\fR\&. See io:fread/3 for a detailed description of the available formatting options\&. It is assumed that \fIString\fR contains whole lines\&. It returns:
.RS 2
.TP 4
.B
\fI{ok, InputList, LeftOverChars}\fR:
The string was read\&. \fIInputList\fR is the list of successfully matched and read items, and \fILeftOverChars\fR are the input characters not used\&.
.TP 4
.B
\fI{more, RestFormat, Nchars, InputStack}\fR:
The string was read, but more input is needed in order to complete the original format string\&. \fIRestFormat\fR is the remaining format string, \fINChars\fR the number of characters scanned, and \fIInputStack\fR is the reversed list of inputs matched up to that point\&.
.TP 4
.B
\fI{error, What}\fR:
The read operation failed and the parameter \fIWhat\fR gives a hint about the error\&.
.RE
.LP
Example:

.nf
3> io_lib:fread("~f~f~f", "15\&.6 17\&.3e-6 24\&.5")\&.

{ok,[15\&.6,1\&.73e-5,24\&.5],[]}
.fi
.RE
.LP
.B
fread(Continuation, String, Format) -> Return
.br
.RS
.TP
Types
Continuation = see below
.br
String = Format = string()
.br
Return = {done, Result, LeftOverChars} | {more, Continuation}
.br
Result = {ok, InputList} | eof | {error, What}
.br
InputList = chars()
.br
What = term()()
.br
LeftOverChars = string()
.br
.RE
.RS
.LP
This is the re-entrant formatted reader\&. The continuation of the first call to the functions must be \fI[]\fR\&. Refer to Armstrong, Virding, Williams, \&'Concurrent Programming in Erlang\&', Chapter 13 for a complete description of how the re-entrant input scheme works\&.
.LP
The function returns:
.RS 2
.TP 4
.B
\fI{done, Result, LeftOverChars}\fR:
The input is complete\&. The result is one of the following:
.RS 4
.LP

.RS 2
.TP 4
.B
\fI{ok, InputList}\fR:
The string was read\&. \fIInputList\fR is the list of successfully matched and read items, and \fILeftOverChars\fR are the remaining characters\&.
.TP 4
.B
\fIeof\fR:
End of file has been encountered\&. \fILeftOverChars\fR are the input characters not used\&.
.TP 4
.B
\fI{error, What}\fR:
An error occurred and the parameter \fIWhat\fR gives a hint about the error\&.
.RE
.RE
.TP 4
.B
\fI{more, Continuation}\fR:
More data is required to build a term\&. \fIContinuation\fR must be passed to \fIfread/3\fR, when more data becomes available\&.
.RE
.RE
.LP
.B
write_atom(Atom) -> chars()
.br
.RS
.TP
Types
Atom = atom()
.br
.RE
.RS
.LP
Returns the list of characters needed to print the atom \fIAtom\fR\&.
.RE
.LP
.B
write_string(String) -> chars()
.br
.RS
.TP
Types
String = string()
.br
.RE
.RS
.LP
Returns the list of characters needed to print \fIString\fR as a string\&.
.RE
.LP
.B
write_char(Integer) -> chars()
.br
.RS
.TP
Types
Integer = int()
.br
.RE
.RS
.LP
Returns the list of characters needed to print a character constant\&.
.RE
.LP
.B
indentation(String, StartIndent) -> int()
.br
.RS
.TP
Types
String = string()
.br
StartIndent = int()
.br
.RE
.RS
.LP
Returns the indentation if \fIString\fR has been printed, starting at \fIStartIndent\fR\&.
.RE
.LP
.B
char_list(Term) -> bool()
.br
.RS
.TP
Types
Term = term()
.br
.RE
.RS
.LP
Returns \fItrue\fR if \fITerm\fR is a flat list of characters, otherwise it returns \fIfalse\fR\&.
.RE
.LP
.B
deep_char_list(Term) -> bool()
.br
.RS
.TP
Types
Term = term()
.br
.RE
.RS
.LP
Returns \fItrue\fR if \fITerm\fR is a, possibly deep, list of characters, otherwise it returns \fIfalse\fR\&.
.RE
.LP
.B
printable_list(Term) -> bool()
.br
.RS
.TP
Types
Term = term()
.br
.RE
.RS
.LP
Returns \fItrue\fR if \fITerm\fR is a flat list of printable characters, otherwise it returns \fIfalse\fR\&.
.RE