Changeset 4216

Show
Ignore:
Timestamp:
04/22/08 08:09:59 (2 months ago)
Author:
pmoura
Message:
Updated the definitions of the predicate valid/1 for the library objects "list", "list(Type)", "numberlist", "set", "set(Type)", "varlist" to fail for lists with unbound tails after discussion with Jan Wielemaker and Ulrich Neumerkel.
Location:
trunk
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • trunk/library/list.lgt

    r3687 r4216  
    55 
    66    :- info([ 
    7         version is 1.3, 
     7        version is 1.4, 
    88        author is 'Paulo Moura', 
    9         date is 2006/12/21, 
     9        date is 2008/4/22, 
    1010        comment is 'List predicates.']). 
    1111 
     
    203203        suffix(List, Tail). 
    204204 
    205     valid(List) :- 
    206         nonvar(List), 
    207         \+ \+ valid2(List). 
    208  
    209     valid2([]). 
    210     valid2([_| List]) :- 
    211         valid2(List). 
     205    valid(-) :-     % catch variables and lists with unbound tails 
     206        !, 
     207        fail. 
     208    valid([]). 
     209    valid([_| List]) :- 
     210        valid(List). 
    212211 
    213212:- end_object. 
  • trunk/library/list1.lgt

    r2737 r4216  
    44 
    55    :- info([ 
    6         version is 1.01, 
     6        version is 1.1, 
    77        author is 'Paulo Moura', 
    8         date is 2006/4/25, 
     8        date is 2008/4/22, 
    99        comment is 'List predicates with elements constrained to a single type.']). 
    1010 
    11     valid(List) :- 
    12         nonvar(List), 
     11    valid(-) :-     % catch variables and lists with unbound tails 
     12        !, 
     13        fail. 
     14    valid([]). 
     15    valid([Element| List]) :- 
    1316        parameter(1, Type), 
    14         \+ \+ valid(List, Type). 
    15  
    16     valid([], _). 
    17     valid([Value| List], Type) :- 
    18         Type::valid(Value), 
    19         valid(List, Type). 
     17        Type::valid(Element), 
     18        valid(List). 
    2019 
    2120:- end_object. 
  • trunk/library/numberlist.lgt

    r3567 r4216  
    55 
    66    :- info([ 
    7         version is 1.1, 
     7        version is 1.2, 
    88        author is 'Paulo Moura', 
    9         date is 2007/4/20, 
     9        date is 2008/4/22, 
    1010        comment is 'List of numbers predicates.']). 
    1111 
     
    5757        sum(Ns, Acc2, Sum). 
    5858 
    59     valid(List) :- 
    60         nonvar(List), 
    61         \+ \+ valid2(List). 
    62  
    63     valid2([]). 
    64     valid2([Head| Tail]) :- 
    65         number(Head), 
    66         valid2(Tail). 
     59    valid(-) :-     % catch variables and lists with unbound tails 
     60        !, 
     61        fail. 
     62    valid([]). 
     63    valid([Element| List]) :- 
     64        number(Element), 
     65        valid(List). 
    6766 
    6867:- end_object. 
  • trunk/library/set.lgt

    r4191 r4216  
    55 
    66    :- info([ 
    7         version is 1.0, 
     7        version is 1.1, 
    88        author is 'Paulo Moura', 
    9         date is 2000/7/24, 
     9        date is 2008/4/22, 
    1010        comment is 'Set predicates implemented using ordered lists. Uses ==/2 for element comparison and standard term ordering.']). 
    1111 
     
    179179        union([Head1| Tail1], Tail2, Union). 
    180180 
    181     valid(Set) :- 
    182         nonvar(Set), 
    183         valid2(Set). 
     181    valid(-) :-             % catch variables 
     182        !, 
     183        fail. 
     184    valid([]) :- 
     185        !. 
     186    valid([Element| Set]) :- 
     187        check_order(Set, Element). 
    184188 
    185     valid2([]) :- 
     189    check_order(-, _) :-    % catch unbound tails 
     190        !, 
     191        fail. 
     192    check_order([], _) :- 
    186193        !. 
    187     valid2([_]) :- 
    188         !. 
    189     valid2([Element1, Element2| Set]) :- 
    190         Element1 @< Element2, 
    191         valid2([Element2| Set]). 
     194    check_order([Element2| Set], Element1) :- 
     195        Element2 @> Element1, 
     196        check_order(Set, Element2). 
    192197 
    193198:- end_object. 
  • trunk/library/set1.lgt

    r2737 r4216  
    44 
    55    :- info([ 
    6         version is 1.01, 
     6        version is 1.1, 
    77        author is 'Paulo Moura', 
    8         date is 2006/4/25, 
     8        date is 2008/4/22, 
    99        comment is 'Set predicates with elements constrained to a single type.']). 
    1010 
    11     valid(Set) :- 
    12         nonvar(Set), 
     11    valid(-) :-             % catch variables 
     12        !, 
     13        fail. 
     14    valid([]) :- 
     15        !. 
     16    valid([Element| Set]) :- 
     17        check_order(Set, Element). 
     18 
     19    check_order(-, _) :-    % catch unbound tails 
     20        !, 
     21        fail. 
     22    check_order([], _) :- 
     23        !. 
     24    check_order([Element2| Set], Element1) :- 
    1325        parameter(1, Type), 
    14         \+ \+ valid(Set, Type). 
    15  
    16     valid([], _) :- 
    17         !. 
    18     valid([Element], Type) :- 
    19         !, 
    20         Type::valid(Element). 
    21     valid([Element1, Element2| Set], Type) :- 
    22         Element1 @< Element2, 
    2326        Type::valid(Element1), 
    2427        Type::valid(Element2), 
    25         valid([Element2| Set], Type). 
     28        Element2 @> Element1, 
     29        check_order(Set, Element2). 
    2630 
    2731:- end_object. 
  • trunk/library/varlist.lgt

    r3687 r4216  
    44 
    55    :- info([ 
    6         version is 1.0, 
     6        version is 1.1, 
    77        author is 'Paulo Moura', 
    8         date is 2000/7/24, 
     8        date is 2008/4/22, 
    99        comment is 'List of variables predicates.']). 
    1010 
     
    2626        prefix(Tail1, Tail2). 
    2727 
    28     valid(List) :- 
    29         nonvar(List), 
    30         \+ \+ valid2(List). 
    31  
    32     valid2([]). 
    33     valid2([Head| Tail]) :- 
    34         var(Head), 
    35         valid2(Tail). 
     28    valid(-) :-     % catch variables and lists with unbound tails 
     29        !, 
     30        fail. 
     31    valid([]). 
     32    valid([Element| List]) :- 
     33        var(Element), 
     34        valid(List). 
    3635 
    3736:- end_object. 
  • trunk/RELEASE_NOTES.txt

    r4214 r4216  
    6262    installation script to use the "C:\lgtsvn" as base. Simplified manual  
    6363    installation instructions. 
     64 
     65    Updated the definitions of the predicate valid/1 for the library objects  
     66    "list", "list(Type)", "numberlist", "set", "set(Type)", "varlist" to fail  
     67    for lists with unbound tails after discussion with Jan Wielemaker and  
     68    Ulrich Neumerkel. 
    6469 
    6570    Added a simple example, "debug_hooks", of using compilation hooks and