1% BEGIN LICENSE BLOCK 2% Version: CMPL 1.1 3% 4% The contents of this file are subject to the Cisco-style Mozilla Public 5% License Version 1.1 (the "License"); you may not use this file except 6% in compliance with the License. You may obtain a copy of the License 7% at www.eclipse-clp.org/license. 8% 9% Software distributed under the License is distributed on an "AS IS" 10% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 11% the License for the specific language governing rights and limitations 12% under the License. 13% 14% The Original Code is The ECLiPSe Constraint Logic Programming System. 15% The Initial Developer of the Original Code is Cisco Systems, Inc. 16% Portions created by the Initial Developer are 17% Copyright (C) 1995-2006 Cisco Systems, Inc. All Rights Reserved. 18% 19% Contributor(s): Thierry Le Provost, ECRC. 20% Contributor(s): Mark Wallace, IC-Parc and ICL. 21% 22% END LICENSE BLOCK 23 24:- use_module(propia). 25%:- lib(propia). 26 27tests(File) :- 28 open(File,write,Filecomm), 29 set_stream(output,Filecomm), 30 ( t(_), fail ; 31 set_stream(output,stdout), 32 close(Filecomm) ). 33 34wt(N) :- write('Test No. '), writeln(N). 35 36btest(Goal) :- 37 term_variables(Goal,List), 38 write('Goal = '), write(List), writeln(':'), 39 write(' '), writeln(Goal), 40 subcall((Goal,wake),D), 41 write('Answer = '), mprintf(List), nl, 42 writeln('Delayed goals = '), write(' '), writelist(D). 43 44%mprintf([]) :- !,write('[]'). 45%mprintf(Term) :- printf('%QPmw',Term). 46 47 48mprintf(Var) :- var(Var), !, printf('%QPmw',Var). 49mprintf([] ) :- !. 50mprintf(Atom) :- atomic(Atom), !, printf('%QPmw',Atom). 51mprintf([H|T]) :- !, write('['), mpl([H|T]), write(']'). 52mprintf(Term) :- Term=..[F|Args], write(F), 53 mprintargs(Args). 54mprintargs(Args) :- write('('),mpl(Args),write(')'). 55 56mpl([H|T]) :- var(T), !, mprintf(H), write('|'), mprintf(T). 57mpl([H]) :- !, mprintf(H). 58mpl([H|T]) :- mprintf(H), write(', '), mpl(T). 59 60 61writelist([]) :- writeln(none), nl. 62writelist([H|T]) :- writeln(H), wl(T). 63wl([]) :- nl. 64wl([H|T]) :- writeln(H), wl(T). 65 66%:- use_module('/home/lp/mark/propia/propia'). 67 68 69mymember(H,[H|_T]). 70mymember(X,[_Y|T]) :- mymember(X,T). 71 72 73 and(true,true,true). 74 and(true,false,false). 75 and(false,true,false). 76 and(false,false,false). 77 78 79p(1,a). 80p(2,f(_Z)). 81p(3,3). 82 83delay element(_,List,_) if var(List). 84element(1,[H|_Tail],H). 85element(N,[_H|Tail],Val) :- 86 plus(M,1,N), 87 element(M,Tail,Val). 88 89gp_element(I,L,V) :- element(I,L,V) infers most. 90 91q(1,f(a)). 92q(2,f(b)). 93q(3,c). 94 95t(1) :- wt(1), btest(mymember(_X,[a,b,c]) infers most). 96 97t(2) :- wt(2), btest(mymember(_X,_Y) infers most). 98 99 100t(5) :- wt(5), btest((and(X,Y,_Z) infers most, X=Y)). 101 102 103t(7) :- wt(7), btest(p(_X,_Y) infers most). 104 105t(9) :- wt(9), btest(p(2,_Y) infers most). 106 107t(10) :- wt(10), btest(p(_X,_Y) infers unique). 108 109t(11) :- wt(11), btest(p(X,X) infers unique). 110 111t(12) :- wt(12), btest(p(2,_X) infers unique). 112 113t(13) :- wt(13), btest(p(1,_Y) infers consistent). 114 115t(14) :- wt(14), btest(p(1,a) infers consistent). 116 117t(19) :- wt(19), btest(q(_X,_Y) infers most). 118 119t(20) :- wt(20), btest(( gp_element(_I,_L,_V) )). 120 121 122t(22) :- wt(22), btest(( p(_X,f(_Z)) infers most )). 123 124 125t(24) :- wt(24), btest(( q(X,f(Y)) infers unique, 126 member(Y,[b,c,d]) infers most 127 )). 128 129 130