[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: "distinct" predicate
From: |
Henk Vandecasteele |
Subject: |
Re: "distinct" predicate |
Date: |
Thu, 31 Oct 2002 10:59:52 +0100 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.1) Gecko/20020823 Netscape/7.0 |
Defining the predicate as follows should do the job:
distinct(L):-
sort(L, SortedL), %sort all elements in L and removes duplicates
same_length(L, SortedL). % if duplicates have been removed,
% length will differ, and fail.
same_length([],[]).
same_length([_|List1], [_|List2]):-
same_length(List1, List2).
Henk
Abhinav-Bhardwaj wrote:
hi,
is there any way by which i can specify a rule say
distinct..which succeeds only when all the terms in a list
are distinct.
for eg:
?- distinct([a, b, c, d]).
yes
?- distinct([a, b, a, d]).
no
thanks in advance,
regards,
Abhinav
_______________________________________________
Users-prolog mailing list
address@hidden
http://mail.gnu.org/mailman/listinfo/users-prolog