03.06.2013 Views

Turbo Prolog

Turbo Prolog

Turbo Prolog

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

5 Tutorial III: <strong>Turbo</strong> <strong>Prolog</strong>'s<br />

Relentless Search for Solutions<br />

This chapter falls into two main parts. In the first, we examine in detail the process<br />

<strong>Turbo</strong> <strong>Prolog</strong> uses when trying to match a goal with a clause. This process is called<br />

unification and corresponds to parameter passing in other programming languages.<br />

In the second part, you'll learn how to control <strong>Turbo</strong> <strong>Prolog</strong>'s search for solutions of<br />

goals. This will include techniques that make it possible for a program to carry out a task<br />

which would otherwise be impossible, either because the search would take too long<br />

or (less likely with <strong>Turbo</strong> <strong>Prolog</strong>) because the system would run out of free memory.<br />

MATCHING THINGS UP:<br />

THE UNIFICATION OF TERMS<br />

Consider Program 13 in terms of the (external) goal<br />

written_by(X,y).<br />

1* Program 13 *1<br />

domains<br />

title, author symbol<br />

pages integer<br />

publication book(title,page)<br />

predicates<br />

written_by(author,publication)<br />

long_novel(Title)<br />

clauses<br />

written_by(fleming,book("DR NO",210)).<br />

written_by(melville,book("MOBY DICK",bOO))<br />

long_novel(Title):-written_by(_,book(Title,Length)),<br />

Length> 300.<br />

When <strong>Turbo</strong> <strong>Prolog</strong> tries to fulfill the goal, it must try each of the clauses for the<br />

predicate written-.by in turn, trying to get a match between the parameters X and Yand<br />

the parameters in each clause for written_by. This term matching operation is called<br />

unification.<br />

51

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

Saved successfully!

Ooh no, something went wrong!