Using memberd/2
based on library(reif)
available for SICStus|SWI, you get determinism in many cases:
?- memberd(a, [a,b]).
true.
?- memberd(a, [a,a]).
true.
?- memberd(a, [a,X]).
true.
?- memberd(a, [a|Xs]).
true.
Compare this to member/2
:
?- member(a, [a,b]).
true
; false. % leftover choicepoint
?- member(a, [a,a]).
true
; true. % redundant solution
?- member(a, [a,X]).
true
; X = a. % redundant solution
?- member(a, [a|Xs]).
true
; Xs = [a|_A] % redundant answer
; Xs = [_A, a|_B] % redundant answer
; Xs = [_A, _B, a|_C] % redundant answer
; ... .
And still the implementation of memberd/2
produces different answers, when necessary
?- memberd(a, [X,Y]).
X = a
; Y = a, dif(X, a)
; false.
Even in this case, memberd/2
avoids the redundancy of member/2
:
?- member(a, [X,Y]).
X = a
; Y = a. % partially redundant
These two answers are partially redundant: X = a, Y = a
is described by both!
?- member(a, [X,Y]), X = a, Y = a.
X = Y, Y = a
; X = Y, Y = a. % redundant solution