append([], List, List) :- !. % cut as confirming the choice of rule. append([Head|Tail], List, [Head|Rest]) :- append(Tail, List, Rest). % | ?- append([the,cat],[sat,on,the,mat], R). % % R = [the,cat,sat,on,the,mat] % % yes % | ?- append(X, Y, [the,cat,sat,on,the,mat]). % % X = [] % Y = [the,cat,sat,on,the,mat] ; % % no % | ?- % The ! (cut operator) prevents backtracking from % reconsidering alternative options for this predicate after the % cut has been passed. A cut commits the search % to the predicate choice and the variable assignments made so far. % The pressing of the ; key now results in failure, % since there are no alternative choices to be made. The example % here is of a red cut, there are two types of cut, red and green. % A green cut does not alter the search but makes it more efficient by reducing % unnecessary search. Green cuts are typically used to prevent backtracking from % trying mutually exclusive cases which are known to be impossible. % Red cuts fundamentally alter the program search. % A red cut prevents a search from reaching certain % areas of the search, and alters the behaviour of the predicate. % Cuts should be carefully considered before being used.