The following is based on the reification of the concept of equality / inequality .
First we define list_memberd_t/3 , which behaves the same as memberd_truth/3 but has a different order of arguments:
list_memberd_t([] ,_,false). list_memberd_t([Y|Ys],X,Truth) :- if_(X=Y, Truth=true, list_memberd_t(Ys,X,Truth)). list_memberd_truth(Xs,X,Truth) :- list_memberd_t(Xs,X,Truth).
For brevity, define memberd_t/3 based on list_memberd_t/3 :
memberd_t(X,Xs,Truth) :- list_memberd_t(Xs,X,Truth).
As a parallel with library(apply) , define tinclude/3 :
:- meta_predicate tinclude(2,?,?). tinclude(P_2,Xs,Zs) :- list_tinclude_list(Xs,P_2,Zs). list_tinclude_list([], _P_2,[]). list_tinclude_list([E|Es],P_2,Fs0) :- if_(call(P_2,E), Fs0 = [E|Fs], Fs0 = Fs), list_tinclude_list(Es,P_2,Fs).
tfilter/3 is another name for tinclude/3 :
tfilter(P_2,As,Bs) :- tinclude(P_2,As,Bs).
Next, we define the meta predicate texclude/3 , the opposite of tinclude/3 :
:- meta_predicate texclude(2,?,?). texclude(P_2,Xs,Zs) :- list_texclude_list(Xs,P_2,Zs). list_texclude_list([],_,[]). list_texclude_list([E|Es],P_2,Fs0) :- if_(call(P_2,E), Fs0 = Fs, Fs0 = [E|Fs]), list_texclude_list(Es,P_2,Fs).
Now let's use them together!
?- texclude(list_memberd_truth([a,e,i,o,u]), [d,e,l,e,t,e,' ',v,o,w,e,l,s,' ',i,n,' ',a,' ',l,i,s,t], Filtered). Filtered = [d, l, t, ' ',v, w, l,s,' ', n,' ', ' ',l, s,t].
Edit
As an alternative to using texclude/3 above, use tinclude/3 with the auxiliary predicate not/3 to translate the true value:
:- meta_predicate not(2,?,?). not(P_2,X,Truth) :- call(P_2,X,Truth0), truth_flipped(Truth0,Truth). truth_flipped(true,false). truth_flipped(false,true).
Request example:
?- tinclude(not(list_memberd_truth([a,e,i,o,u])), [d,e,l,e,t,e,' ',v,o,w,e,l,s,' ',i,n,' ',a,' ',l,i,s,t], Filtered). Filtered = [d, l, t, ' ',v, w, l,s,' ', n,' ', ' ',l, s,t].