Changeset 4485 for trunk/library

Show
Ignore:
Timestamp:
10/05/08 11:05:01 (3 months ago)
Author:
pmoura
Message:

Added a predicate partition/4 to the library entities "metap" and "meta".

Location:
trunk/library
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/library/meta.lgt

    r4382 r4485  
    44 
    55    :- info([ 
    6         version is 2.1, 
    7         date is 2008/7/16, 
     6        version is 2.2, 
     7        date is 2008/10/5, 
    88        author is 'Paulo Moura', 
    99        comment is 'Some useful meta-predicates.']). 
     
    1616    :- meta_predicate(filter(1, *, *)). 
    1717    filter(_, [], []) :- !. 
    18     filter(Closure, [Arg| Args], List) :- 
     18    filter(Closure, [Arg| Args], In) :- 
    1919        (   call(Closure, Arg) -> 
    20             List = [Arg| Args2] 
    21         ;   List = Args2 
     20            In = [Arg| RIn] 
     21        ;   In = RIn 
    2222        ), 
    23         filter(Closure, Args, Args2). 
     23        filter(Closure, Args, RIn). 
     24 
     25    :- meta_predicate(partition(1, *, *, *)). 
     26    partition(_, [], [], []) :- !. 
     27    partition(Closure, [Arg| Args], In, Out) :- 
     28        (   call(Closure, Arg) -> 
     29            In = [Arg| RIn], 
     30            Out = ROut 
     31        ;   In = RIn, 
     32            Out = [Arg| ROut] 
     33        ), 
     34        partition(Closure, Args, RIn, ROut). 
    2435 
    2536    :- meta_predicate(ignore(::)). 
  • trunk/library/metap.lgt

    r4382 r4485  
    33 
    44    :- info([ 
    5         version is 3.0, 
    6         date is 2008/7/16, 
     5        version is 3.1, 
     6        date is 2008/10/5, 
    77        author is 'Paulo Moura', 
    88        comment is 'Useful meta-predicates protocol.']). 
     
    1919    :- info(filter/3, [ 
    2020        comment is 'Returns a list of all list elements that satisfy a predicate.', 
    21         argnames is ['Predicate', 'In', 'Out']]). 
     21        argnames is ['Closure', 'List', 'In']]). 
     22 
     23    :- public(partition/4). 
     24    :- meta_predicate(partition(1, *, *, *)). 
     25    :- mode(partition(+callable, +list, -list, -list), one). 
     26    :- info(partition/4, [ 
     27        comment is 'Partition a list of elements in two lists using a predicate.', 
     28        argnames is ['Closure', 'List', 'In', 'Out']]). 
    2229 
    2330    :- public(ignore/1). 
     
    3340    :- info(map/3, [ 
    3441        comment is 'List mapping predicate taken arguments from two lists of elements.', 
    35         argnames is ['Predicate', 'List1', 'List2']]). 
     42        argnames is ['Closure', 'List1', 'List2']]). 
    3643 
    3744    :- public(map/4). 
     
    4047    :- info(map/4, [ 
    4148        comment is 'List mapping predicate taken arguments from three lists of elements.', 
    42         argnames is ['Predicate', 'List1', 'List2', 'List3']]). 
     49        argnames is ['Closure', 'List1', 'List2', 'List3']]). 
    4350 
    4451    :- public(map/5). 
     
    4754    :- info(map/5, [ 
    4855        comment is 'List mapping predicate taken arguments from four lists of elements.', 
    49         argnames is ['Predicate', 'List1', 'List2', 'List3', 'List4']]). 
     56        argnames is ['Closure', 'List1', 'List2', 'List3', 'List4']]). 
    5057 
    5158    :- public(succeeds/2). 
     
    5461    :- info(succeeds/2, [ 
    5562        comment is 'True if the predicate succeeds for each list element.', 
    56         argnames is ['Predicate', 'List']]). 
     63        argnames is ['Closure', 'List']]). 
    5764 
    5865:- end_protocol.