5.1 Outputting terms
The write/1 predicate takes a single argument, which must be a valid Prolog
term. The built-in predicate nl/0 has also been used many times previously. It takes no arguments. Evaluating a nl goal causes a new line to be output to
the current output stream.
Example:
?- write(college),nl.
college
Yes
5.2 Inputting term
The built-in predicate read/1 is provided to input terms. It takes a single argument,
which must be a variable.
In the input stream, the term must be followed by a dot ('.') and at least one white space character, such as space or newline. The dot and white space characters are read in but are not considered part of the term.
If the argument variable is already bound the goal succeeds if and only if the
input term is identical to the previously bound value.
?- X=rooney,read(X).
: rooney.
X = rooney
5.3 Input and Output using computer
Although input and output of terms is easy, the use of quotes and full
stops can be not always suitable.
A much better approach for
problems of this kind is to input a character at a time. To do this it is first necessary
to know about the ASCII value of a character..
All printing characters and many non-printing characters (such as space and
tab) have a corresponding ASCII (American Standard Code for Information
- 1. The predicate readin is defined recursively. It causes a single character to be
Prologue to take input from the current input stream and take the output from the current output stream. For example, the keyboard as input devices and monitors as a means of output. Input and output can also be raised through files and files. Users can open and close the input and output with a variety of files, but can only process one type of file it at the same time.
5.8 File Output : Changing the Current Output Stream
Predicate tell / 1
Current output stream can be changed using this Predicate. With this Predicate, the file was not opened will be deleted and replaced with the current output stream.
Predicate told / 0
This Predicate causes the file name changed to the user's terminal.
Predicate telling / 1
This Predicate causes the variable bound by the name of the current output stream.
5.9 File Input: Changing the Current Input Stream
Current input stream can be changed using the Predicate see, followed by the atom, as an example, see ( 'myfile.txt'). This Predicate causes the file name changed to current input stream. see the Predicate consists of several parts. First, the order seen / 0 which causes current input file into the user's terminal.
Reading from Files: End of File
If the end of the file found when evaluating Predicate get (X) or get0 (X), variable X will be bound to specific numerical values. If the range is 0-255 ASCII code, the code that appears before the code is 1.
Reading from Files: End of Record
End of the line indicated by karakterASCII input value 13. End of the record indicated by 2 values of 13 ASCII characters followed by 10.
No comments:
Post a Comment