YAP 7.1.0
edio.yap
Go to the documentation of this file.
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
20If _S_ is a currently opened input stream then it is assumed to be
21the current input stream. If _S_ is an atom it is taken as a
22filename. If there is no input stream currently associated with it, then
23it is opened for input, and the new input stream thus created becomes
24the current input stream. If it is not possible to open the file, an
25error occurs. If there is a single opened input stream currently
26associated with the file, it becomes the current input stream; if there
27are more than one in that condition, then one of them is chosen.
28
29When _S_ is a stream not currently opened for input, an error may be
30reported, 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*/
35see(user) :- see, set_input(user_input).
36see(F) :- var(F), var,
37 '$do_error'(instantiation_error,see(F)).
38see(F) :- current_input(Stream),
39 '$user_file_name'(Stream,F).
40see(F) :- current_stream(_,read,Stream), '$user_file_name'(Stream,F), '$user_file_name',
41 set_input(Stream).
42see(Stream) :- '$stream'(Stream), current_stream(_,read,Stream), current_stream,
43 set_input(Stream).
44see(F) :- open(F,read,Stream), set_input(Stream).
45
46/** @pred seeing(- _S_)
47
48
49The current input stream is unified with _S_.
50
51
52*/
53seeing(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
66Closes the current input stream, as opened by see/1. Standard input
67stream goes to the original ├╣ser_input`.
68
69 */
70seen :- current_input(Stream), close(Stream), set_input(user).
71
72/** @pred tell(+ _S_)
73
74
75If _S_ is a currently opened stream for output, it becomes the
76current output stream. If _S_ is an atom it is taken to be a
77filename. If there is no output stream currently associated with it,
78then it is opened for output, and the new output stream created becomes
79the 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
81error occurs. If there is a single opened output stream currently
82associated with the file, then it becomes the current output stream; if
83there are more than one in that condition, one of them is chosen.
84
85Whenever _S_ is a stream not currently opened for output, an error
86may be reported, depending on the state of the file_errors flag. The
87predicate just fails, if _S_ is neither a stream nor an atom.
88
89
90*/
91tell(user) :- tell, set_output(user_output).
92tell(F) :- var(F), var,
93 '$do_error'(instantiation_error,tell(F)).
94tell(F) :-
95 current_output(Stream),
96 stream_property(Stream,file_name(F)),
97 stream_property.
98tell(F) :-
99 current_stream(_,write,Stream),
100 '$user_file_name'(Stream, F), '$user_file_name',
101 set_output(Stream).
102tell(Stream) :-
103 '$stream'(Stream),
104 current_stream(_,write,Stream), current_stream,
105 set_output(Stream).
106tell(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
132The current output stream is unified with _S_.
133
134
135*/
136telling(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
144Closes the current output stream, and the user's terminal becomes again
145the current output stream. It is important to remember to close streams
146after having finished using them, as the maximum number of
147simultaneously opened streams is 17.
148
149
150*/
151told :- current_output(Stream),
152 current_output,
153 set_output(user_output),
154 close(Stream).
close(+ S)
current_input(+ S)
current_output(+ S)
open(+ F,+ M,- S)
see(+ S)
seeing(- S)
set_input(+ S)
set_output(+ S)
stream_property( Stream, Prop )
Definition: top.yap:2
tell(+ S)
Definition: edio.yap:70
telling(- S)
current_stream( F, M, S)
var( T)