At its core, Prolog is a logical deduction engine with the following core mechanics:
Prolog source code is a collection of rules of the form
left_hand_side :- right_hand_side. This reads as: the left hand side is true if the right hand side is true.
Lower case symbols, called atoms, are concrete values whilst symbols starting with an upper case letter are variables.
If the right hand side is just the atom
true then the rule can be abbreviated as
left_hand_side. This is called a fact.
Facts can have arguments. For example:
parent(james, sam). parent(mary, sam). female(mary).
We have recorded 3 facts about the closed world that James and Mary are both parents of Sam and that Mary is a woman.
Rules can contain variables. Every instances of the same variable in a rule must resolve to the same value. For example:
mother(X, Y) :- parent(X, Y), female(X).
This rule states that X is a mother of Y if X is a parent of Y and X is female.
We can then inquire the system for the validity of facts:
?- female(mary). true ?- mother(mary, sam). true ?- mother(john, sam). false
More interestingly, we can go the other way around, asking the system for known values that can make a query true:
?- mother(Who, sam). Who = mary ?- parent(Who, sam). Who = john; Who = mary
A Concise Introduction To Prolog
Kinda like a Learn X in Y minutes page where X is Prolog.
Prolog syntax and semantics
Also another cheatsheet-like page.
A book-length tutorial on building an adventure game in Prolog.
Learn Prolog Now!
I personally learned Prolog through this guide.
The Power of Prolog
Good stuff and modern but rather hard to follow.
[TO BE WRITTEN]