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.
it_is(carnivore) if<br />
positive(does,eat_meat).<br />
it_is(carnivore) if<br />
positive(has,pointed_teeth) and<br />
positive(has,claws) and<br />
positive(has,forward_eyes).<br />
it_is(ungulate) if<br />
it_is(mammal) and<br />
positive(has,hooves).<br />
it_is(ungulate) if<br />
it_is(mammal) and<br />
positive(does,chew_cud).<br />
We can ask questions like<br />
does it have hair?<br />
We want to add corresponding clauses to <strong>Turbo</strong> <strong>Prolog</strong>'s database so it can reason<br />
with the new clauses. We can add facts to the <strong>Turbo</strong> <strong>Prolog</strong> database via the asserta<br />
standard predicate. Thus<br />
asserta(xpositive(has,black_stripes))<br />
will cause<br />
xpositive(has,black_stripes).<br />
to be added to the <strong>Turbo</strong> <strong>Prolog</strong> database, provided xpositive has been declared in a<br />
database declaration at the top of the program:<br />
domains<br />
database xpositive(symbol,symbol)<br />
predicates<br />
clauses<br />
Clauses for a predicate declared in a database declaration must not contain any<br />
rules-only facts. For a more detailed discussion of database predicates, see Chapter<br />
II, "Dynamic Databases."<br />
Our database declaration will be as follows:<br />
database xpositive(symbol,symbol)<br />
xnegative(symbol,symbol)<br />
The relationship between xpositive and positive is contained in the first of two rules for<br />
positive:<br />
positive(X,y) if xpositive(X,Y),!.<br />
In other words, xpositive is the database equivalent of positive. We have a similar rule<br />
for negative:<br />
negative(X,y) if xnegative(X,Y),!.<br />
Tutorial VIII: Spreading Your Wings 111