Developed in 1972 by Alain Colmerauer and Phillipe Roussel, Prolog is a logic programming language that gained popularity in natural-language processing. Now, the venerable language provides the programming foundation for a wide variety of problems, from scheduling to expert systems. You can use this rules-based language for expressing logic and asking questions. Like SQL, Prolog works on databases, but the data will consist of logical rules and relationships. Like SQL, Prolog has two parts: one to express the data and one to query the data. In Prolog, the data is in the form of logical rules. These are the building blocks:
Facts. A fact is a basic assertion about some world. (Babe is a pig; pigs like mud.)
Rules. A rule is an inference about the facts in that world. (An animal likes mud if it is a pig.)
Query. A query is a question about that world. (Does Babe like mud?)
Facts and rules will go into a knowledge base. A Prolog compiler compiles the knowledge base into a form that’s efficient for queries. As we walk through these examples, you’ll use Prolog to express your knowledge base. Then, you’ll do direct retrieval of data and also use Prolog to link rules together to tell you something you might not have known.
Enough background. Let’s get started.