MC logo

Prolog Session Example

  Prolog Examples

Family Relations>>
Here is a transcript of a Prolog session making queries against the proglog examples.

bennet 1001%pl
Welcome to SWI-Prolog (Version 3.1.2)
Copyright (c) 1993-1998 University of Amsterdam.  All rights reserved.

For help, use ?- help(Topic). or ?- apropos(Word).

?- consult(family).
family compiled, 0.00 sec, 5,564 bytes.

Yes
?- parent(dennis, adam).

Yes
?- parent(lola,carrie).

No
?- parent(X,adam).

X = carrie ;

X = dennis ;

No
?- brother(dave, X).

X = tom ;

No
?- sister(dave, X).

No
?- ancestor(X,theo).

X = tom ;

X = lola ;

X = bill ;

X = phyl ;

X = bonnie_h ;

X = tom_h ;

No
?- ancestor(tom_h, X).

X = lola ;

X = carrie ;

X = bonnie ;

X = theo ;

X = rachel ;

X = adam ;

No
?- brother(X,Y).

X = dave
Y = tom ;

X = tom
Y = dave ;

X = theo
Y = bonnie ;

X = theo
Y = rachel 

Yes
?- consult(list).
list compiled, 0.00 sec, 1,232 bytes.

Yes
?- app([a,b,c],[d,e],X).

X = [a, b, c, d, e] ;

No
?- app([a,b,c],X,[a,b,c,d,e,f]).

X = [d, e, f] ;

No
?- app([a,b],X,[a,c,e]).

No
?- app(X,Y,[a,b,c]).

X = []
Y = [a, b, c] ;

X = [a]
Y = [b, c] ;

X = [a, b]
Y = [c] ;

X = [a, b, c]
Y = [] ;

No
?- app([A,B|[e,u,t]],[u,t],Q).

A = _G255
B = _G258
Q = [_G255, _G258, e, u, t, u, t] ;

No
?- len(X,[a,b,c]).

X = 3 ;

No
?- len(4,Y).

Y = [_G230, _G233, _G236, _G239] ;

^C
Action (h for help) ? abort

Execution Aborted

?- sum_list(X,[3,4,9,8]).

X = 24 ;

No
?- sum_list(10,[4,Y]).
[WARNING: Arguments are not sufficiently instantiated]
 ^ Exception: ( 10) _L145 is _G210+0 ? abort

Execution Aborted

?- consult(puz).
puz compiled, 0.01 sec, 12,988 bytes.

Yes
?- to_flight(X,Y,Z).

X = [11, 50]
Y = [alphaville, discovery, clarksville, hope_springs, ephemeral, fortuna, alph
aville]
Z = [e4, w1, e5, w8, e2, w12] ;

No
?- tadd([3,10],[1,15],X).

X = [4, 25] ;

No
?- tadd([3,45], [2,25], X).

X = [6, 10] ;

No
?- at(discovery, Ti, Tr).

Ti = [9, 10]
Tr = e2 ;

Ti = [8, 10]
Tr = e3 ;

Ti = [7, 50]
Tr = e4 ;

Ti = [8, 50]
Tr = e6 ;

Ti = [8, 10]
Tr = e7 ;

Ti = [10, 30]
Tr = e11 ;

Ti = [8, 0]
Tr = w1 ;

Ti = [9, 0]
Tr = w2 

Yes
?- trip(clarksville, [8,20], hope_springs, Arrtime, Stations, Trains).

Arrtime = [12, 0]
Stations = [clarksville, hope_springs]
Trains = [e2] ;

Arrtime = [9, 0]
Stations = [clarksville, hope_springs]
Trains = [e5] ;

Arrtime = [11, 30]
Stations = [clarksville, discovery, hope_springs]
Trains = [e2, e11] ;

Arrtime = [11, 30]
Stations = [clarksville, fortuna, hope_springs]
Trains = [e2, e11] ;

Arrtime = [12, 0]
Stations = [clarksville, gamesport, hope_springs]
Trains = [e5, e2] 

Yes
?- halt.
bennet 1003%
Family Relations>>