6.5 Rules, Goals and Subgoals
A rule expresses something dynamic, i.e., something that can be computed.
This contrasts with facts, which are static.
The syntax of a rule consist of three things: a head, an entails-symbol (":-"), a body, and a period (".").
head :- body.
In particular, a head can be a structure, which is what you will use most often.
The body consists of a comma-separated list of subgoals. To explain what a subgoal is, we must first explain what a goal is.
A goal is something that Prolog+CG can seek to satisfy. That is, it tries to prove that the goal is true.
We have already met goals in the form of queries. For example:
Here, "is_philosopher(Peirce)" is a goal which Prolog+CG must prove or satisfy in order for the query to succeed.
A subgoal is a goal in a rule or query. There can be more than one subgoal in a query or the body of a rule.
CarnivoreEatsAnimal(L) :- gr(L, G), subsume([Carnivore]<-AGNT-[Eat]-PTNT->[Animal], G).
Here, the body of the rule consists of two subgoals:
The head of the rule can be "satisfied" or "proved" if the body of the rule can be "satisfied" or proved.
The body of the rule can be "satisfied" or "proved" if all of its subgoals can be "satisfied" or proved. This is done in the order in which they are listed.
Thus a rule consists of a head, an "entails" symbol, a body, and a period.
The head can be proved if the body can be proved. The body can be proved if all its subgoals can be proved, in the order in which they are listed.
A subgoal is a goal in a rule or query. A goal is something that Prolog+CG will seek to satisfy or prove.
PrevLite: 6.4 Facts
NextLite: 6.6 Clauses and predicates
Prev: 6.4 Facts
Up: 6 Prolog for CG users
Next: 6.6 Clauses and predicates