Programming Languages---Course 66.443
male(albert). male(edward). female(alice). female(victoria). parents(edward, victoria, albert). parents(alice,victoria, albert).
procyon.cs.rpi.edu% /sw1/prolog/bin/api
Aquarius Prolog version 1.0 top-level (SPARC, SunOS)
| ?- consult('~/public/proglang/queen.pro').
yes
| ?- female(alice).
yes
| ?- female(victoria).
yes
| ?- female(albert).
no
| ?- female(jane).
no
| ?- female(X). X = alice ; X = victoria ; no
| ?- parents(edward,X,Y). X = victoria, Y = albert ; no
| ?- parents(X,victoria,Y). X = edward, Y = albert ; X = alice, Y = albert ; no
sister_of(X,Y) :- female(X), parents(X,M,F), parents(Y,M,F).That is, X is a sister of Y if X is female and X and Y have the same parents. In Prolog notation, :- means ``if'' and the subgoals on the right are required to be satisfied simultaneously (``anded'' together), with the same assignment to variables, in order for the goal on the left to be satisfied. After adding this rule to our file, we proceed as follows:
| ?- reconsult('~/public/proglang/queen.pro').
yes
| ?- sister_of(alice,edward).
yes
| ?- sister_of(alice,X).
X = edward ;
X = alice ;
no
sister_of(X,Y) :- female(X), parents(X,M,F), parents(Y,M,F), X \== Y.
| ?- reconsult('~/public/proglang/queen.pro').
yes
| ?- sister_of(alice,X).
X = edward ;
no
| ?- sister_of(alice, edward).
sister_of( X, Y) :-
female(X), parents(X, M, F), parents(Y, M, F), X \== Y.
male(albert).
male(edward).
female(alice).
female(victoria).
parents(edward, victoria, albert).
parents(alice, victoria, albert).
| ?- sister_of(alice, X).
sister_of( X, Y) :-
female(X), parents(X, M, F), parents(Y, M, F), X \== Y.
male(albert).
male(edward).
female(alice).
female(victoria).
parents(edward, victoria, albert).
parents(alice, victoria, albert).