The following is a simple Prolog program:
The first line can be read, ``Socrates is a man.'' It is a base clause, which represents a simple fact.
man(socrates). mortal(X) :- man(X).
The second line can be read, ``X is mortal if X is a man;'' in other words, ``All men are mortal.'' This is a clause, or rule, for determining when its input X is ``mortal.'' (The symbol ``:-'', sometimes called a turnstile, is pronounced ``if''.) We can test the program by asking the question:
that is, ``Is Socrates mortal?'' (The ``
| ?- mortal(socrates).
| ?-'' is the computer's prompt for a question.) Prolog will respond ``
yes''. Another question we may ask is:
That is, ``Who (X) is mortal?'' Prolog will respond ``
| ?- mortal(X).
X = socrates''.