home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / plbin.zip / pl / boot / apply.pl < prev    next >
Text File  |  1992-05-26  |  1KB  |  56 lines

  1. /*  apply.pl,v 1.1.1.1 1992/05/26 11:51:21 jan Exp
  2.  
  3.     Copyright (c) 1990 Jan Wielemaker. All rights reserved.
  4.     jan@swi.psy.uva.nl
  5.  
  6.     Purpose: calling predicates
  7. */
  8.  
  9. :- module($apply, [
  10.     checklist/2, 
  11.     maplist/3, 
  12.     sublist/3, 
  13.     forall/2]).
  14.  
  15. :- module_transparent
  16.     checklist/2, 
  17.     maplist/3, 
  18.     sublist/3, 
  19.     forall/2.
  20.  
  21. %    checklist(+Goal, +List)
  22. %    True if Goal can succesfully be applied on all elements of List.
  23.  
  24. checklist(_, []).
  25. checklist(Goal, [Elem|Tail]) :-
  26.     $apply(Goal, [Elem]), 
  27.     checklist(Goal, Tail).
  28.  
  29. %    maplist(+Goal, +List1, ?List2)
  30. %    True if Goal can succesfully be applied to all succesive pairs
  31. %    of elements of List1 and List2.
  32.  
  33. maplist(_, [], []).
  34. maplist(Goal, [Elem1|Tail1], [Elem2|Tail2]) :-
  35.     $apply(Goal, [Elem1, Elem2]), 
  36.     maplist(Goal, Tail1, Tail2).
  37.  
  38. %    sublist(+Goal, +List1, ?List2)
  39. %    Succeeds if List2 unifies with a list holding those terms for wich
  40. %    apply(Goal, Elem) succeeds.
  41.  
  42. sublist(_, [], []) :- !.
  43. sublist(Goal, [H|T], Sub) :-
  44.     $apply(Goal, [H]), !, 
  45.     Sub = [H|R], 
  46.     sublist(Goal, T, R).
  47. sublist(Goal, [_|T], R) :-
  48.     sublist(Goal, T, R).
  49.  
  50. %    forall(+Condition, +Action)
  51. %    True if Action if true for all variable bindings for which Condition
  52. %    if true.
  53.  
  54. forall(Cond, Action) :-
  55.     \+ (Cond, \+ Action).
  56.