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.

The clauses section contains a collection of facts and rules. The facts<br />

likes(ellen,tennis).<br />

likes(john,football).<br />

likes(torn,baseball).<br />

likes(eric,swirnrning).<br />

likes(rnark,tennis).<br />

correspond to these statements in English:<br />

ellen likes tennis.<br />

john likes football.<br />

tom likes baseball.<br />

eric likes swimming.<br />

mark likes tennis.<br />

Notice that there is no information in these facts about whether or not<br />

likes(bill,baseball).<br />

To use <strong>Prolog</strong> to discover if bill likes baseball, we can execute the above <strong>Prolog</strong> program<br />

with<br />

likes(bill,baseball).<br />

as our goal. When attempting to satisfy this goal, the <strong>Prolog</strong> system will use the rule<br />

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

In ordinary English, this rule corresponds to:<br />

bill likes X if tom likes X.<br />

Type the above program into your computer following the method outlined in Chapter<br />

2 and Run it. When the system responds in the dialog window,<br />

enter<br />

<strong>Turbo</strong> <strong>Prolog</strong> replies<br />

True<br />

Goal :<br />

Goal :<br />

likes(bill,baseball).<br />

in the dialog window and waits for you to give another goal. <strong>Turbo</strong> <strong>Prolog</strong> has combined<br />

the rule<br />

likes(bill,X) if likes(torn,X)<br />

with the fact<br />

likes(torn,baseball)<br />

to decide that<br />

likes(bill,baseball)<br />

is true. Now enter the new goal<br />

18 <strong>Turbo</strong> <strong>Prolog</strong> Owner's Handbook

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

Saved successfully!

Ooh no, something went wrong!