Page 219 - DCAP506_ARTIFICIAL_INTELLIGENCE
P. 219
Unit 14: Prolog
Predicate Purpose Notes
get_byte(?ByteCode) Read a byte
get_char(?Char) Read a character
get_code(?CharCode) Read a character
get_until(+SearchChar, ?Text, ?EndChar) Read up to a specified character
nl Write new line
print(@Term) Write a term
put_byte(+ByteCode) Write a byte
put_char(+Char) Write a character
put_code(+CharCode) Write a character
read(?Term) Read a term
read_term(?Term, +Options) Read a term with control options
skip_line Skip input line
write(@Term) Write a term
write_canonical(@Term) Write a term in normal structure representation
and in single quotes
write_formatted(+Format, @TermList) Write terms with formatting
write_term(@Term, @Options) Write a term using operator notation
writeq(@Term) Write a term in single quotes, using operator
notation
14.10.2 Explicitly Specifying Streams for Input/Output
Input and output can be executed also from and to an explicitly specified stream. It is not
required to redefine current streams only for a single input or output operation. Rather, a
predicate with an extra argument for the stream can be utilized.
If you desire to implement the input/output from or to a stream, you must first open this stream
previous to the first read or write operation. If the stream is to be a pipe, you should first create
it with the predicate unix_make_pipe(-Pipename). Pipename is produced by the Prolog system
when the pipe is generated.
Open for file by calling pipe by calling
Reading open(file(Filename), read, X) open(pipe(Pipename), read, Y)
Writing open(file(Filename), write, X) open(pipe(Pipename), write, Y)
Appending open(file(Filename), append, X) —
1cmi [t]13cmYou can also open a stream (typically a file) by calling see/1, tell/1 or error_
tell/1.
1cmi [t]13cmFile names which enclose special or Prolog-specific characters, or which start with
an uppercase letter, must be contained in single quotes.
1cmi [t]13cmYou can open a stream either for reading or for writing, but not for both concurrently.
LOVELY PROFESSIONAL UNIVERSITY 213