.. include:: global.rst .. _Overview: Prolog Tutorial ################################### Notes ==================================== The 3 basic ideas in prolog: * Facts: Assertions about the world (e.g., "Socrates is a man"). * Rules: Conditional statements (e.g., "If someone is a man, they are mortal"). * Queries: Questions you ask the system (e.g., "Is Socrates mortal?"). Facts ----------------- .. code-block:: parent(bob, alice). parent(bob, bill). parent(alice, charlie). Rules ----------------- .. code-block:: grandparent(X, Z) :- parent(X, Y), parent(Y, Z). Queries ----------------- ?- parent(bob, alice). Output: true. Ask a Variable question: ?- parent(bob, Who). Output: Who = alice ; (Press ; to see the next result) Output: Who = bill. .. csv-table:: Syntax Rules :header: "Feature", "Syntax Example", "Notes" Atoms,"apple, socrates",Must be lowercase. Variables,"X, Person",Must be uppercase. "The ""If""",:-,Separates the head from the body. "The ""And""",",",Used to link conditions in a rule. "The ""Or""",;,Used to provide alternatives. The End,.,Every statement must end with a period. Code ==================================== .. literalinclude:: ./other/prolog/test.pl