The following is a simple Prolog program:
man(socrates).
mortal(X) :- man(X).
The first line can be read, ``Socrates is a man.'' It is a base
clause, which represents a simple fact.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:
| ?- mortal(socrates).
that is, ``Is Socrates mortal?'' (The ``| ?-
'' is the
computer's prompt for a question.) Prolog will respond
``yes
''. Another question we may ask is:
| ?- mortal(X).
That is, ``Who (X) is mortal?'' Prolog will respond ``X = socrates
''.
|