[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: "distinct" predicate
From: |
Robert Wolf |
Subject: |
RE: "distinct" predicate |
Date: |
Fri, 1 Nov 2002 09:23:58 +1030 |
Abhinav-Bhardwaj,
There is a "beutiful" prolog "native" solution to "dsitinct" problem.
You can wirite it easily yourself.
Here are the hints:
1. Empty list is basically "distinct".
2. The list is "distinct" if:
a) the "head" element is not on the "tail" list AND
b) the "tail" list is "distinct"
3. Your dialect of prolog may already have a predicate checking if
something is on the list.
4. If not, you can write it easily yourself.
5. An element is on the list if:
a) it is the same as the "head" element of the list OR
b) it is on the "tail" list
Something like: (I use another dialect, so you may have to modify
syntax, sorry)
distinct ([]) :- .
distinct ([a]) :- .
distinct ([head : tail]) :-
NOT (is_on_the_list (head, tail)),
distinct (tail).
is_on_the_list (head, [head :tail]) :- .
is_on_the_list (head, [something :tail]) :-
is_on_the_list (head, tail).
Best regards and "happy prologing"...
Robert P. Wolf
address@hidden
-----Original Message-----
From: Abhinav-Bhardwaj [mailto:address@hidden
Sent: Thursday, 31 October 2002 7:55 PM
To: address@hidden
Subject: "distinct" predicate
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