Lesson goal: More introduction to Prolog

Previous: Introduction to Prolog: Facts and goals | Home | Next: Adding two fractions

In the last lesson, you got a taste of Prolog facts and goals. Let's continue this now, with an example that might make you think "Hmmm...how did the computer do that?"

We'll use the likes fact again, but with a twist.
likes(ellen,tennis).
likes(bill,X):-likes(tom,X).
Move the mouse over a dotted box for more information.

Reading likes(bill,X) :- likes(tom,X). means: bill will like item X if tom likes item X. So when Prolog tries to see if bill likes item X, it first has to determine if tom also likes item X (which is can determine from the raw facts).

Now you try. Before running this code, look at it and see if you can tell if bill likes baseball or not. How do you know?

Type your code here:


See your results here: