Oct 27, 2003 ------------- - Basics of PROLOG - Supplying facts - constants and predicates are written in lower case - Asking questions - variables start with a capital letter - list notation in prolog [X|Y] X::Y .(X,Y) X::Y [X,Y] X::Y::nil [X] X::nil [X,Y|Z] X::Y::Z [X,Y,Z|W] X::Y::Z::W - the following things are nonsense! X|Y [X|Y,Z] [X|Y|Z] - simple rules - head and body of rule Files used in this session animal(cow). animal(dog). animal(rabbit). animal(rogerrabbit). animal(yak). animal(emu). likes(justin, kathy). likes(kathy, apples). likes(justin, justin). ihave([pencil, pen, watch]). ihave([cs3304, cs4804, cs4234, cs3204]). ihave([nolife]). ihave([[toyota, 1998, corolla], [honda, 1997, civic]]). ihave([book, [pen1, pen2], [newdollarbill]]). ihave(nolife). cscourse(cs3304). cscourse(cs4804). bwcourse(bw101). easy(X) :- cscourse(X). easy(bw101). Transcript of session: ---------------------- ?- consult(animal). % animal compiled 0.00 sec, 936 bytes Yes ?- animal(X). X = cow Yes ?- animal(X). X = cow ; X = dog ; X = rabbit ; X = rogerrabbit ; X = yak ; X = emu ; No ?- animal(WhatIwant). WhatIwant = cow ; WhatIwant = dog ; WhatIwant = rabbit ; WhatIwant = rogerrabbit ; WhatIwant = yak ; WhatIwant = emu ; No ?- animal(whatiwant). No ?- animal(whatIwant). No ?- animal(X), animal(Y). X = cow Y = cow ; X = cow Y = dog ; X = cow Y = rabbit ; X = cow Y = rogerrabbit ; X = cow Y = yak ; X = cow Y = emu ; X = dog Y = cow ; X = dog Y = dog ; X = dog Y = rabbit ; X = dog Y = rogerrabbit ; X = dog Y = yak ; X = dog Y = emu ; X = rabbit Y = cow ; X = rabbit Y = dog ; X = rabbit Y = rabbit ; X = rabbit Y = rogerrabbit ; X = rabbit Y = yak ; X = rabbit Y = emu ; X = rogerrabbit Y = cow ; X = rogerrabbit Y = dog ; X = rogerrabbit Y = rabbit ; X = rogerrabbit Y = rogerrabbit ; X = rogerrabbit Y = yak ; X = rogerrabbit Y = emu ; X = yak Y = cow ; X = yak Y = dog ; X = yak Y = rabbit ; X = yak Y = rogerrabbit ; X = yak Y = yak ; X = yak Y = emu ; X = emu Y = cow ; X = emu Y = dog ; X = emu Y = rabbit ; X = emu Y = rogerrabbit ; X = emu Y = yak ; X = emu Y = emu ; No ?- animal(X), animal(Y), X\=Y. X = cow Y = dog ; X = cow Y = rabbit ; X = cow Y = rogerrabbit Yes ?- consult(likes). % likes compiled 0.00 sec, 704 bytes Yes ?- likes(justin, X), likes(X, apples). X = kathy ; No ?- consult(list). % list compiled 0.00 sec, 0 bytes Yes ?- ihave(X). X = [pencil, pen, watch] ; X = [cs3304, cs4804, cs4234, cs3204] ; X = [nolife] ; X = [[toyota, 1998, corolla], [honda, 1997, civic]] ; X = [book, [pen1, pen2], [newdollarbill]] ; X = nolife ; No ?- ihave([X|Y]). X = pencil Y = [pen, watch] ; X = cs3304 Y = [cs4804, cs4234, cs3204] ; X = nolife Y = [] ; X = [toyota, 1998, corolla] Y = [[honda, 1997, civic]] ; X = book Y = [[pen1, pen2], [newdollarbill]] ; No ?- ihave([X,Y|Z]). X = pencil Y = pen Z = [watch] ; X = cs3304 Y = cs4804 Z = [cs4234, cs3204] ; X = [toyota, 1998, corolla] Y = [honda, 1997, civic] Z = [] ; X = book Y = [pen1, pen2] Z = [[newdollarbill]] ; No ?- ihave([X,Y]). X = [toyota, 1998, corolla] Y = [honda, 1997, civic] ; No ?- ihave([X]). X = nolife ; No ?- ihave([X,Y,Z]). X = pencil Y = pen Z = watch ; X = book Y = [pen1, pen2] Z = [newdollarbill] ; No ?- consult(courses). % courses compiled 0.00 sec, 1,028 bytes Yes ?- cscourse(X). X = cs3304 ; X = cs4804 ; No ?- easy(X). X = cs3304 ; X = cs4804 ; X = bw101 ; No ?- % halt