Starting Prolog
Prolog system is straightforward. From one person to other person, the precise details of Prolog will vary. Prolog will produce a number of lines of headings in the starting, which is followed by a line. It contains just
?-
The above symbol shows the system prompt. The prompt is used to show that the Prolog system is ready to specify one or more goals of sequence to the user. Using a full stop, we can terminate the sequence of goals.
For example:
?- write(‘Welcome to Tutor Aspire’),nl,write(‘Example of Prolog’),nl.
nl indicates ‘start a new line’. When we press ‘return’ key, the above line will show the effect like this:
Welcome to Tutor Aspire
Example of Prolog
yes
?- prompt shows the sequence of goal which is entered by the user. The user will not type the prompt. Prolog system will automatically generate this prompt. It means that it is ready to receive a sequence of goals.
The above example shows a sequence of goals entered by the user like this:
write(‘Welcome to Tutor Aspire’), write(‘Example of Prolog’), nl(twice).
Consider the following sequence of goals:
write(‘Welcome to Tutor Aspire’),nl,write(‘Example of Prolog’),nl.
The above sequence of goals has to succeed in order to be succeeded.
- write(‘Welcome to Tutor Aspire’)
On the screen of the user, Welcome to Tutor Aspire has to be displayed - nl
On the screen of the user, a new line has to be output - write(‘Example of Prolog’)
On the screen of the user, Example of Prolog has to be displayed - nl
On the screen of the user, a new line has to be output
All these goals will simply achieve by the Prolog system by outputting the line of text to the screen of the user. To show that the goals have succeeded, we will output yes.
The Prolog system predefined the meanings of nl and write. Write and nl are called as built-in predicates.
Halt and statistics are the two other built-in predicates. In almost all Prolog versions, these predicates are provided as standard.
- ?- halt.
The above command is used to terminate the Prolog system. - ?- statistics.
This command will cause the Prolog system statistics. This statistics feature is mainly used to experienced user. In statistics, the following things will generate:
The above output ends with Yes. Yes, specify that the goal has succeeded, as halt, statistics, and many other built-in predicates always do. When they evaluate, their values produce, which lies in the side-effects.
‘Query’ is a sequence of one or more goals. These goals are entered by the user at the prompt. In this tutorial, we are generally using the ‘sequence of goals’ term.