next up previous contents
Next: Implementing queries with constants Up: Unit 3: Prolog: queries Previous: Querying facts

Rules

Variables are not restricted to queries, but can be used in facts, too. For example, classify(Anything,entity) could be taken to mean ``Whatever it is, classify anything as an entity''.

A more interesting application is to relate relations to each other in terms of the objects they share. For example, salt, pepper condiments, and let us assume that mustard and vinegar are also condiments. Let us also note that condiments are spices. In logical terms we can therefore deduce that mustard is a spice, though this statement is not actually in the database:

All condiments are spices. tex2html_wrap_inline691
Mustard is a condiment. condiment(mustard)
Mustard is a spice. spice(mustard)

This is formulated in Prolog in the following way:

All condiments are spices. spice(X) :- condiment(X).
Mustard is a condiment. condiment(mustard).
Is mustard a spice? spice(mustard).
Yes. yes.

Relations between relations, in this sense, using the operator `:-', are known as RULES. No more illustrations will be given here; rules are the main ingredient of any interesting Prolog programme, and will be introduced in the context of specific problems.



Dafydd Gibbon
Thu Feb 12 11:04:00 MET 1998