% examples from LP course; % these run under the Terzo implementation of lambda Prolog % to run: % take copy of this file, cd to the directory containing examples.mod. % Session runs as follows: % => /afs/inf.ed.ac.uk/group/dreamers/group/bin/Terzo % Terzo lambda-Prolog, Version 1.2b, Built Thu Jun 16 01:54:13 2011 % [reading file /afs/inf.ed.ac.uk/group/dreamers/group/src/terzo-1.2b/lib/terzo.rc] % [closed file /afs/inf.ed.ac.uk/group/dreamers/group/src/terzo-1.2b/lib/terzo.rc] % Terzo> #load "examples.mod". % [reading file examples.mod] % module examples % [closed file examples.mod] % Terzo> #query examples. % ?- sterile(J). % % J = j ; % % no more solutions % ?- ?- #end. % Terzo> #quit. % => % example from McCarthy module examples. kind i type. type sterile (i -> o). type in (i -> i -> o). type heated (i -> o). type bug (i -> o). type dead (i -> o). type j i. sterile Jar :- pi x\ ( (bug x) => (in x Jar) => (dead x) ). dead X :- heated Y, in X Y, bug X. heated j. % query: % % heated(J). % J = j. type ancestor i -> i -> o. type ancestor2 i -> i -> o. type parent i -> i -> o. ancestor X Y :- parent X Y. ancestor X Z :- parent X Y, ancestor Y Z. type trans (A -> A -> o) -> A -> A -> o. trans Pred X Y :- Pred X Y. trans Pred X Z :- Pred X Y, trans Pred Y Z. ancestor2 X Y :- trans parent X Y. % test data type jane i. type moses i. type john i. type james i. type peter i. parent jane moses. parent john peter. parent jane john. parent james peter. % ?- ancestor2 X Y. type mapfun (A -> B) -> list A -> list B -> o. type mappred (A -> B -> o) -> list A -> list B -> o. mapfun F nil nil. mapfun F (X :: K) ((F X) :: L) :- mapfun F K L. % ?- mapfun (x\ x + x) (3 :: 4 :: 5 :: nil) Y. % Y = 3 + 3 :: 4 + 4 :: 5 + 5 :: nil % ?- mapfun (x\ (x + x)) X ((3 + 3) :: ( 8 + 8) :: nil). % X = 3 :: 8 :: nil % ?- mapfun F (3 :: 8 :: nil) ((3 + 3) :: ( 8 + 8) :: nil). % F = x\ x + x mappred P nil nil. mappred P (X :: L) (Y :: K) :- P X Y, mappred P L K. % ?- mappred parent (jane :: john :: nil) L. % L = moses :: peter :: nil ; % L = john :: peter :: nil ; % no more solutions % ?- mappred parent X (john :: peter :: nil). % X = jane :: john :: nil ; % X = jane :: james :: nil ; % no more solutions