Prolog is a declarative logic programming language: programs define facts and rules, while queries ask for values that make those rules true. Unification fills holes in terms through substitution, and backtracking searches alternative solutions. Together, they turn logical relationships into executable queries. section 10.3
Shared interests become a query
Facts such as likes(Alice, scuba), likes(Bob, scuba), and likes(Carol, birdwatching) can support the rule “if likes(X, Y) and likes(Z, Y), then compatible(X, Z).” Querying compatible(Bob, Q) first unifies Bob’s interests with scuba, then backtracks to birdwatching. The resulting values for Q are Alice, Bob, and Carol, but not David. section 10.3
if likes(Bob, Y) and likes(Q, Y) then compatible(Bob, Q)
Use the rule form to inspect how a general compatibility relation becomes a concrete subproblem involving Bob and an unknown person. section 10.3
Rules may combine several relationships, such as requiring both a shared friend and a shared interest. The same unification machinery also solves first-order logic problems and can represent type-inference problems, linking logic programming with generic types and omitted type information. section 10.3
