Inferences

Where facts are generally specific, rules are generic. A specific fact might be that Bruce likes Joe. A rule might be that people who like the same things like each other.

A rule is a logical conclusion. A rule comes in the form hypothesis :- facts. We read it as “hypothesis if facts.” Let’s add a few more facts and some rules now. Add these lines to the bottom of your db.pl file:

 tweets​(​jill​, ​greeting​).
 tweets​(​anna​, ​gossip​).
 
 follows​(​eric​, ​jill​).
 follows​(​joe​, ​anna​).
 follows​(​eric​, ​joe​).
 follows​(​jill​, ​joe​).

We add a few facts. “tweets(jill, greeting)” means “Jill sends the tweet named greeting.” Now that tweets have been sent, we can look at who can see them. In the Twitter universe, that means ...

Get Programmer Passport: Prolog now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.