I can't understand clearly the use of cut. For example in this case: flatten, is it really needed? It works for me even without both cut predicates (I tried removing). What are the cases that can cause the backtracking going to the cut? Removing the cuts you have the same implementation of the book "The art of prolog" (Shapiro E.,Sterling L.) that is:
flatten([X|Xs],Ys) :-
flatten(X,Ysl),
flatten(Xs,Ys2),
append(Ys1,Ys2,Ys).
flatten(X,[X]) :-
constant(X),
X\=[].
flatten([],[]).
which leads me to another question: is it necessary in the second clause to check if it's not a list? If it's a single term won't unify with the first clause...isn't it?
constant/1
predicate? Is it the same asatomic/1
? – Sergey Kalinichenko