03.06.2013 Views

Turbo Prolog

Turbo Prolog

Turbo Prolog

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

3 Tutorial I:<br />

Five Simple Programs<br />

This is the first of eight chapters giving a step-by-step tutorial introduction to the <strong>Turbo</strong><br />

<strong>Prolog</strong> language. It begins with a study of the structure of a <strong>Turbo</strong> <strong>Prolog</strong> program, first<br />

by means of a simple example and then by examining the fundamental components of<br />

a program, one by one. In every case, our starting point will be a motivating example<br />

with the threads drawn together a little more formally at the end of the chapter.<br />

(Chapters II and 12 contain very precise definitions of all <strong>Turbo</strong> <strong>Prolog</strong> features. At this<br />

stage in the tutorial it's getting started that matters.)<br />

Apart from program structure, the two other important ideas introduced in this chapter<br />

are backtracking (which is how <strong>Prolog</strong> searches for all possible solutions to a goal)<br />

and how to make <strong>Prolog</strong> check if something is not true-at least as far as the available<br />

information makes it possible to determine.<br />

THE STRUCTURE OF<br />

A TURBO PROLOG PROGRAM<br />

Consider the following example program:<br />

1* Program 1 *1<br />

domains<br />

person, activity = symbol<br />

predicates<br />

likes(person,activity)<br />

clauses<br />

likes(ellen,tennis).<br />

likes(john,football).<br />

likes(tom,baseball).<br />

likes(eric,swimming).<br />

likes(mark,tennis).<br />

likes(bill,X) if likes(tom,X).<br />

17

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!