different(Xs, Ys) :-
member(X, Xs),
non_member(X, Ys).
different(Xs, Ys) :-
member(Y, Ys),
non_member(Y, Xs).
While this definition using member/2
and non_member/2
is almost1 perfect from a declarative viewpoint, it produces redundant solutions for certain queries and leaves choice points all around.
What is a definition that improves upon this (in a pure manner probably using if_/3
and (=)/3
) such that exactly the same set of solutions is described by different/2
but is determinate at least for ground queries (thus does not leave any useless choice points open) and omits (if possible) any redundant answer?
1
Actually, different([a|nonlist],[]), different([],[b|nonlist])
succeeds. It could equally fail. So a solution that fails for both is fine (maybe even finer).
(Much inspired by @repeat's last answer, the names are still too clumsy)
Back to the roots! This variant is very close to the code given by the OP in the question.
The following is based on
if_/3
andmemberd_t/3
.Here is a ground query:
And here's the (more general) query I used in previous answers: