Show
Ignore:
Timestamp:
04/22/08 08:09:59 (4 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.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • 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.