YAP
7.1.0
edio.yap
Go to the documentation of this file.
1
%
2
% Edinburgh IO.
3
/**
4
* @file edio.yap
5
* @author VITOR SANTOS COSTA <vsc@VITORs-MBP.lan>
6
* @date Wed Jan 20 01:07:02 2016
7
*
8
* @brief Input/Output according to the DEC-10 Prolog. PLease consider using the ISO
9
* standard predicates for new code.
10
*
11
*
12
*/
13
14
15
%
16
17
/** @pred see(+ _S_)
18
19
20
If _S_ is a currently opened input stream then it is assumed to be
21
the current input stream. If _S_ is an atom it is taken as a
22
filename. If there is no input stream currently associated with it, then
23
it is opened for input, and the new input stream thus created becomes
24
the current input stream. If it is not possible to open the file, an
25
error occurs. If there is a single opened input stream currently
26
associated with the file, it becomes the current input stream; if there
27
are more than one in that condition, then one of them is chosen.
28
29
When _S_ is a stream not currently opened for input, an error may be
30
reported, depending on the state of the `file_errors` flag. If
31
_S_ is neither a stream nor an atom the predicates just fails.
32
33
34
*/
35
see
(user)
:-
see,
set_input
(user_input).
36
see
(
F
)
:-
var
(
F
),
var,
37
'$do_error'(instantiation_error,see(
F
)).
38
see
(
F
)
:-
current_input
(
Stream
),
39
'$user_file_name'(
Stream
,
F
).
40
see
(
F
)
:-
current_stream
(
_
,read,
Stream
),
'$user_file_name'(
Stream
,
F
),
'$user_file_name',
41
set_input
(
Stream
).
42
see
(
Stream
)
:-
'$stream'(
Stream
),
current_stream
(
_
,read,
Stream
),
current_stream,
43
set_input
(
Stream
).
44
see
(
F
)
:-
open
(
F
,read,
Stream
),
set_input
(
Stream
).
45
46
/** @pred seeing(- _S_)
47
48
49
The current input stream is unified with _S_.
50
51
52
*/
53
seeing
(
File
)
:-
current_input
(
Stream
),
54
stream_property
(
Stream
,file_name(
NFile
)),
55
(
56
stream_property
(user_input,file_name(
NFile
))
57
->
58
File
=
stream_property
59
;
60
NFile
=
File
61
).
62
63
/** @pred seen
64
65
66
Closes the current input stream, as opened by see/1. Standard input
67
stream goes to the original ùser_input`.
68
69
*/
70
seen
:-
current_input
(
Stream
),
close
(
Stream
),
set_input
(user).
71
72
/** @pred tell(+ _S_)
73
74
75
If _S_ is a currently opened stream for output, it becomes the
76
current output stream. If _S_ is an atom it is taken to be a
77
filename. If there is no output stream currently associated with it,
78
then it is opened for output, and the new output stream created becomes
79
the current output stream. Existing files are clobbered, use append/1 to ext end a file.
80
If it is not possible to open the file, an
81
error occurs. If there is a single opened output stream currently
82
associated with the file, then it becomes the current output stream; if
83
there are more than one in that condition, one of them is chosen.
84
85
Whenever _S_ is a stream not currently opened for output, an error
86
may be reported, depending on the state of the file_errors flag. The
87
predicate just fails, if _S_ is neither a stream nor an atom.
88
89
90
*/
91
tell
(user)
:-
tell,
set_output
(user_output).
92
tell
(
F
)
:-
var
(
F
),
var,
93
'$do_error'(instantiation_error,tell(
F
)).
94
tell
(
F
)
:-
95
current_output
(
Stream
),
96
stream_property
(
Stream
,file_name(
F
)),
97
stream_property.
98
tell
(
F
)
:-
99
current_stream
(
_
,write,
Stream
),
100
'$user_file_name'(
Stream
,
F
),
'$user_file_name',
101
set_output
(
Stream
).
102
tell
(
Stream
)
:-
103
'$stream'(
Stream
),
104
current_stream
(
_
,write,
Stream
),
current_stream,
105
set_output
(
Stream
).
106
tell
(
F
)
:-
107
open
(
F
,write,
Stream
),
108
set_output
(
Stream
).
109
110
/** @pred append(+ _S_)
111
112
113
If _S_ is a currently opened stream for output, it becomes the
114
current output stream. If _S_ is an atom it is taken to be a
115
filename. If there is no output stream currently associated with it,
116
then it is opened for output in *append* mode, that is, by adding new data to the end of the file.
117
The new output stream created becomes
118
the current output stream. If it is not possible to open the file, an
119
error occurs. If there is a single opened output stream currently
120
associated with the file, then it becomes the current output stream; if
121
there are more than one in that condition, one of them is chosen.
122
123
Whenever _S_ is a stream not currently opened for output, an error
124
may be reported, depending on the state of the file_errors flag. The
125
predicate just fails, if _S_ is neither a stream nor an atom.
126
127
128
*/
129
/** @pred telling(- _S_)
130
131
132
The current output stream is unified with _S_.
133
134
135
*/
136
telling
(
File
)
:-
137
current_output
(
Stream
),
138
stream_property
(
Stream
,file_name(
NFile
)),
139
(
stream_property
(user_output,file_name(
NFile
))
->
File
=
stream_property
;
File
=
NFile
).
140
141
/** @pred told
142
143
144
Closes the current output stream, and the user's terminal becomes again
145
the current output stream. It is important to remember to close streams
146
after having finished using them, as the maximum number of
147
simultaneously opened streams is 17.
148
149
150
*/
151
told
:-
current_output
(
Stream
),
152
current_output,
153
set_output
(user_output),
154
close
(
Stream
).
close/1
close(+ S)
current_input/1
current_input(+ S)
current_output/1
current_output(+ S)
open/3
open(+ F,+ M,- S)
see/1
see(+ S)
seeing/1
seeing(- S)
set_input/1
set_input(+ S)
set_output/1
set_output(+ S)
stream_property/2
stream_property( Stream, Prop )
Definition:
top.yap:2
tell/1
tell(+ S)
Definition:
edio.yap:70
telling/1
telling(- S)
current_stream/3
current_stream( F, M, S)
var/1
var( T)
os
edio.yap
Generated by
1.9.3