Navigation  without Java Scripts

How Does Prolog Differ From Other Languages?

The traditional computer languages, such as C, BASIC and Pascal, are procedural languages. In a procedural language, the programmer must provide step by step instructions that tell the computer exactly how to solve a given problem. In other words, the programmer must know how to solve the problem before the computer can do it. The Prolog programmer, on the other hand, only needs to supply a description of the problem and the ground rules for solving it. From there, the Prolog system is left to determine how to find a solution.

Here's a short look at how Prolog works.

Prolog uses facts and rules.

Apart from some initial declarations, a Prolog program essentially consists of a list of logical statements, either in the form of facts, such as

father("John","Mary") "John is the father to Mary"
father("John","Sally") "John is the father to Sally"
father("John","Sam") "John is the father to Sam"
mother("Jeanette","Mary") "Jeanette is the mother to Mary""
mother("Mary","Tom") "Mary is the mother to Tom"

or in the form of rules, such as

sister(X,Y) :- father(Z,X), father(Z,Y). "X and Y are sisters if they have the same father"

X, Y, Z are here variables, which are used to specify bindings between the different relations. Variables can be any name starting with an uppercase letter.

Prolog can make deductions

You can give the Prolog program some goals, for example to conditions:

Goal father("John","Mary"). Prolog will answer true because the goal matches the stored facts.

If you use a variable in the goals, Prolog will find the value for the variable:

Goal father(X,"Mary"). Prolog will answer X="John" because it can look it up in the facts.

There is no difference between using facts and rules, for example if the goal is:

Goal sister(X,"Mary"). Prolog will answer X="Sally" because "Sally" can satisfy the rule for sister.

Similarly, Prolog can use its deductive ability to find all solutions to the problem:

Goal father("John",X).

Prolog will answer
X="Mary"
X="Sally"
X="Sam"

The solutions are found through backtracking where all combinations are tried. This automatic backtracking mechanism combined with the built-in database (the facts) is one of Visual Prolog's most powerful tools.