/* APPLIC : Various application routines.

                                                UTILITY
                                                Lawrence
                                                Updated: 11 September 81
*/

        %%% APPLIC requires module:  LISTRO



  apply(P,Eargs)
        :- ( atom(P),
             NP =.. [P|Eargs]   ;   P =.. [Pred|Oargs],
                                     append(Oargs,Eargs,Nargs),
                                     NP =.. [Pred|Nargs]
           ),
           !,
           NP.



  checkand(P,true) :- !.

  checkand(P,A&B)
        :- !,
           apply(P,[A]),
           checkand(P,B).

  checkand(P,A) :- !, apply(P,[A]).




  checklist(P,[]) :- !.

  checklist(P,[HD|TL])
        :- !,
           apply(P,[HD]),
           checklist(P,TL).



  mapand(P,true,true) :- !.

  mapand(P,A&As,B&Bs)
        :- !,
           apply(P,[A,B]),
           mapand(P,As,Bs).

  mapand(P,A,B) :- !, apply(P,[A,B]).




  maplist(P,[],[]) :- !.

  maplist(P,[X|Xs],[Y|Ys])
        :- !,
           apply(P,[X,Y]),
           maplist(P,Xs,Ys).



  convlist(P,[],[]).

  convlist(P,[X|Xs],[Y|Ys])
        :- apply(P,[X,Y]),
           !,
           convlist(P,Xs,Ys).

  convlist(P,[X|Xs],Ys) :- !, convlist(P,Xs,Ys).



  some(P,[]) :- !, fail.

  some(P,[X|Xs]) :- apply(P,[X]).

  some(P,[X|Xs]) :- !, some(P,Xs).



  sublist(P,[],[]).

  sublist(P,[X|Xs],[X|Ys])
        :- apply(P,[X]),
           !,
           sublist(P,Xs,Ys).

  sublist(P,[X|Xs],Ys) :- !, sublist(P,Xs,Ys).

