Skip to content

Instantly share code, notes, and snippets.

@mindcrime
Created July 5, 2018 23:11
Show Gist options
  • Save mindcrime/d2f9bdad1f3ed7603d041c8f23ecc4f1 to your computer and use it in GitHub Desktop.
Save mindcrime/d2f9bdad1f3ed7603d041c8f23ecc4f1 to your computer and use it in GitHub Desktop.
Prolog samples from Chapter 1 of Clocksin & Mellish
diff(X,Y) :- X \== Y.
male(albert).
male(edward).
female(alice).
female(victoria).
parents(edward, victoria, albert ).
parents(alice, victoria, albert).
sister_of(X,Y) :-
female(X),
diff(X,Y),
parents(X, Mum, Dad ),
parents(Y, Mum, Dad ).
conceived(victoria, edward).
conceived(albert, edward).
conceived(victoria,alice).
conceived(albert, alice).
father(Dad,Child) :- male(Dad),conceived(Dad,Child). /* X is the father of Y */
mother(Mum,Child) :- female(Mum),conceived(Mum,Child). /* X is the mother of Y */
parent(Parent,Child) :- father(Parent,Child).
parent(Parent,Child) :- mother(Parent,Child).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment