next up previous contents
Next: What You Should Up: Some Practical Problems Previous: Satisfy Once Only

Fail Goal Now

We often search for the solution to a goal using several clauses for some predicate. For example, we might have a social security calculation which tries to assign how much money to give a claimant. Here is a fragment of program:

 
calculate_benefit(Claim_Number,Nationality,Age,Other_Details):-

Nationality = british,

calculate_british_entitlement(Age,Other_Details).

calculate_benefit(Claim_Number,Nationality,Age,Other_Details):-

Nationality = martian,

give_up.

calculate_benefit(Claim_Number,Nationality,Age,Other_Details):-

Nationality = french,

calculate_french_entitlement(Age,Other_Details).

If we reach the situation where we realise that the whole search is doomed then we may want to say something informally like `stop this line of approach to the solution and any other corresponding line'. In the above, if we find we are trying to assign benefit to a martian then we make the decision that calculate_benefit/4 should fail and therefore that there is no point in trying to use any remaining clauses to find a solution.

In practice, we need to make use of this kind of action. Again, we are potentially asking Prolog to behave abnormally.

In fact, in all these situations, we are asking Prolog to behave in a non-standard way. Whatever the complications, it is hard top make do without ways to:



Paul Brna
Mon May 24 20:14:48 BST 1999