/* examples to illustrate controlling search in CLP(R) */ /* append with the rules reversed */ append([X|Xs],Ys,[X|Zs]) :- append(Xs,Ys,Zs). append([],Ys,Ys). /* length of a list, without and with a (usually redundant) constraint that the length is non-negative */ not_so_good_length([],0). not_so_good_length([_|Xs],N) :- not_so_good_length(Xs,N-1). length([],0). length([_|Xs],N) :- N>0, length(Xs,N-1). /* the standard definition of member */ member(X,[X|Xs]). member(X,[Y|Ys]) :- member(X,Ys). /* cut (written !) prunes the search tree */ member_cut(X,[X|Xs]) :- !. member_cut(X,[Y|Ys]) :- member_cut(X,Ys). /* member(1,[1,2,3,1]) will succeed twice member_cut(1,[1,2,3,1]) will succeed just once member_cut(X,[1,2,3]) will only give one answer: X=1. */ my_not(X) :- call(X), !, fail. my_not(X).