% Predicates in Lambda Prolog that define some of the `higher-order'
% mapping operations
% This is modified from the standard distribution, to have the function,
% or predicate first.  

module  maps.

  mapfun F nil nil.
  mapfun F [X|L] [(F X)|K] :- mapfun F L K.
  
  mappred P nil nil.
  mappred P (X::L) (Y::K) :- P X Y, mappred P L K.
  
  reduce_pred P (W::nil) F Y :- P W Y.
  reduce_pred P (W::L) F (F Y Z) :- P W Y, reduce_pred P L F Z.
  
  reduce F nil X X.
  reduce F (W::L) X (F W Y) :-  reduce F L X Y.
  
  reduce_eval F L Y Z :- reduce F L Y W, Z is W.
  
  for_each P nil.
  for_each P (X::L) :- P X, for_each P L.
