do :-
write('command: '),
read(Command),
perform(Command).
perform( stop) :- !.
perform( Command) :-
execute( Command),
do.
Until stop is encountered, the program executes user commands.
Possible to write multiple commands to the output stream (i.e. the
terminal - unless specified otherwise).
write_colour(X) :-
colour(X, Colour),
write('The colour of'),
write(X),
write('is'),
write(Colour),
write('.'),
nl.
Once a result to any input and output operation has been obtained, all further results are ignored. Therefore, I/O operations are deterministic in that (while backtracking) they cannot be re-satisfied. Therefore, writing :
write('hello'), fail.
will only produce one output hello and stop.
Possible to read and write a term by doing :
read(X), write(X), fail.
Only one term may be read from the current input stream - the conjunction of goals, i.e. read and write, will then fail because backtracking cannot take place.