Turbo Prolog
Turbo Prolog
Turbo Prolog
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Finally, consider execution of the goal<br />
long_novel (X).<br />
When <strong>Turbo</strong> <strong>Prolog</strong> tries to fulfill a goal, it investigates whether or not there exists a<br />
matching fact or left side of a rule. In this case, the match is with the left side of a rule<br />
long_novel( X )<br />
long_novel(Title):written_by(_,book(Title,Length)),Length>300.<br />
since the free variable X can be unified with any other term and, in particular, another<br />
free variable. Next, <strong>Turbo</strong> <strong>Prolog</strong> makes the first clause on the right side of this rule the<br />
current sub-goal, and unification is achieved with the first fact for written-1Jyas follows:<br />
written_by( Name ,book(Title ,Length))<br />
written_by(fleming,book("DR NOli, 210))<br />
in which Length has become bound to 210.<br />
Now the second clause on the right side of the longJJovel rule becomes the current<br />
sub-goal<br />
Length > 300<br />
Before unification is attempted, the bound variable Length is replaced with the value to<br />
which it is bound, 210. Since<br />
210 > 300<br />
is a legal comparison of two integer values, the comparison is made-and, of course,<br />
returns false. <strong>Turbo</strong> <strong>Prolog</strong> now attempts a different unification of<br />
written_by(Name,book(Title,Length))<br />
(see the next section) and binds Title to "MOBY DICK" and Length to 600. Now<br />
Length > 300<br />
unifies with Length replaced by 600 (the value to which it is bound) and indeed succeeds,<br />
so that longJJovel also succeeds with Title bound to "MOBY DICK". <strong>Turbo</strong><br />
<strong>Prolog</strong> displays<br />
X = "MOBY DICK"<br />
1 Solution<br />
Summary of <strong>Turbo</strong> <strong>Prolog</strong>'s Unification Algorithm<br />
• A free variable can be unified with any term. The variable is then bound to the other<br />
term.<br />
• A constant (an integer, for example) can unify with itself or with a free variable.<br />
• A compound term can unify with another compound term, provided they both<br />
involve the same functor and have the same number of arguments. Further, all the<br />
subterms must unify pairwise. (Lists are treated as a special kind of compound term).<br />
Tutorial III: <strong>Turbo</strong> <strong>Prolog</strong>'s Relentless Search for Solutions 53