Changeset 4216 for trunk/library/set.lgt

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