How can I code member/2 that has determinism for the last element. Currently I am using:
member(X,[X|_]).
member(X,[_|Y]) :- member(X,Y).
When I query the following:
?- member(X,[1,2]).
X = 1 ;
X = 2 ;
No
The interpreter continues searching after returning 2 since there is still a choice point left. How could I implement member/2 so that this does not happen anymore?
But the full semantic of member/2 should be preserved, i.e. answers such as:
?- member(X,Y)
Y = [X|_1] ;
Y = [_1,X|_2] ;
etc..
Should still work as befor.
Bye