Declarative is much different to both imperative and object orientated. It does not have a state nor does it have statements which are followed in sequence. In fact when you first see a declarative program it is quite common not to understand it. Let us consider some simple code

male(bob).

male(fred).

male(barny).

 

female(sally).

female(sarah).

female(hannah).

 

father(fred,bob).

father(bob,barny).

 

grandfather(X,Z) :-

father(X,Y),

father(Y,Z).

 

Note:- The names are in lowercase as uppercase are considered to be variables.

Straight away we have two of the most important parts of a declarative program. The rules and the facts. However can you actually tell what the program does? The answer is that at the moment it does not do anything! What it does do is allow us to ask questions and find out answers. First of all look at the first 3 lines.

 

male(bob).

male(fred).

male(barny).

 

These are three facts. We are saying that bob, fred and barny are all male. By writing this down we are making the basis of our program. To get into the syntax a bit more the male() part is known as a predicate and the words inside the brackets are known as atoms. You do not need to know this terminology for the course however it does help when trying to follow tutorials off the web.

Hopefully you can already work out that the female predicates and the father predicates are all facts as well. We shall now do some basic declarative programming in order to help understand how it works.