/****************************/ /* plug-in architecture */ /* of HCLP interpreter */ /* -----kernel module----- */ /* meta-interpreter */ /* (c) R. Bart‡k */ /* 1996 */ /****************************/ % this module implements a meta-interpreter for solving HCLP programs % it is a first kernel component of plug-in architecture for HCLP % to get a complete HCLP(D,C) interpreter, you need to define procedures % constr_to_hier, solve_constr_hier (in GHSmod.pr) % solve_constr (in FCSmod.pr) :-op(800,xfx,@). % definition of labels/strengths lab([required,strong,prefer,weak]). % main procedure for solving HCLP goals solve(Goal,Answ):- add_subgoal(Goal,[],GoalList), solve(GoalList,[],[],Answ). solve([C@L|T],CurrAnsw,Hier,Answ):-!, add_constr(C,L,CurrAnsw,Hier,NewAnsw,NewHier), solve(T,NewAnsw,NewHier,Answ). solve([G|T],CurrAnsw,Hier,Answ):- reduce(G,CurrAnsw,NewG,NewAnsw), add_subgoal(NewG,T,NewT), solve(NewT,NewAnsw,Hier,Answ). solve([],CurrAnsw,ConstrHier,Answ):- solve_constr_hier(ConstrHier,[CurrAnsw],Answ). reduce(SG,OldAnsw,true,NewAnsw):- system(SG),!, copy_term(SG,CopySG), call(CopySG), solve_constr(SG=CopySG,OldAnsw,NewAnsw). reduce(G,OldAnsw,NewG,NewAnsw):- copy_term(G,CopyG), clause(CopyG,NewG), solve_constr(G=CopyG,OldAnsw,NewAnsw). add_constr(Const,Lab,OldAnsw,OldHier,NewAnsw,NewHier):- lab(Labs), (Labs=[Lab|_] -> solve_constr(Const,OldAnsw,NewAnsw), NewHier=OldHier % required constraints are solved immediately ; constr_to_hier(Const,Lab,OldHier,NewHier), NewAnsw=OldAnsw). % soft constraints are collected %%%%%% auxiliary procedures %%%%%%%%%% stronger(L1,L2):- lab(Ls), stronger(L1,L2,Ls). stronger(L1,L2,[L1|T]):-!,L1\=L2. stronger(L1,L2,[L2|T]):-!,fail. stronger(L1,L2,[_|T]):-stronger(L1,L2,T). member(X,[X|T]). member(X,[Y|T]):- member(X,T). add_subgoal(true,T,T):-!. add_subgoal((A,B),T,NewT):-!, add_subgoal(B,T,SubT), add_subgoal(A,SubT,NewT). add_subgoal(A,T,[A|T]).