2 Logic Programming With Prolog
nl stands for 'start a new line', as will be explained later. Like all other user
input, the above line does not have any effect until the 'return' key is pressed.
Doing so produces the output
Hello World
Welcome to Prolog
yes
followed by a further system prompt ?-.
In this book a sequence of goals entered by the user will generally be shown
preceded by the ?- prompt. The prompt must not be typed by the user. It is
generated automatically by the Prolog system to show that it is ready to receive a
sequence of goals.
In the above example, the user has entered a sequence of four goals:
write('Hello World'), nl (twice) and write('Welcome to Prolog'). The commas
separating the goals signify 'and'.
In order for the sequence of goals
write('Hello World'),nl,write('Welcome to Prolog'),nl
to succeed each of the following goals has to succeed in order:
write('Hello World')
Hello World has to be displayed on the user's screen
nl
a new line has to be output to the user's screen
write('Welcome to Prolog')
Welcome to Prolog has to be displayed on the user's screen
nl
A new line has to be output to the user's screen.
The Prolog system can achieve all these goals simply by outputting lines of text
to the user's screen. It does so and then outputs yes to indicate that the sequence of
goals has succeeded.
From the system's point of view, the important issue is whether or not the
sequence of goals entered by the user succeeds. The generation of output to the
screen is considered much less important and is described as (merely) a side effect
of evaluating the goals write('Hello World') etc.
The meanings of write and nl are pre-defined by the Prolog system. They are
known as built-in predicates, sometimes abbreviated to BIPs.
Two other built-in predicates that are provided as standard in almost all
versions of Prolog are halt and statistics.
?-halt.