Javatpoint Logo
Javatpoint Logo

Prolog Clauses

In Prolog, the program contains a sequence of one or more clauses. The clauses can run over many lines. Using a dot character, a clause can be terminated. This dot character is followed by at least one 'white space' character. The clauses are of two types: facts and rules.

Facts are specified in the form of the head. Head is known as the clause head. It will take in the same way as the goal entered at the prompt by the user. The head of a clause must be a compound term or an atom. Compound terms and atoms are collectively called as call terms.

Examples of facts are as follows:

Rules are specified in the form:

The head is known as the clause of head.

:- is known as the clause neck. It is read as 'if'. The body of the clause is specified by t1, t2, t3, tk. It contains one or more components, and it can be separated using the commas. The goal represents the components. The command is represented by 'and'.

A rule will be read as 'if t1, t2, t3,…., tk are all true, head is true'.

Examples of rules are as follows:

The following program shows another animal program. This program includes facts and rules.

Examples of Animals Program 2 are as follows:

Atoms are rottweiler, siamese, dobermann, etc. which are indicated by initial lower case letters. Variables are A and B, which are indicated by initial lower case letters.

Facts are indicated by the first 18 clauses. Rules are indicated by the final two clauses.

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA