I think the original idea of looking at and evaluating the cause of cuts in real code is a good one. It would surely help to understand how and why we are using cut in practice.
Some of it is clearly because of the people using the language being steeped in procedural or even functional programming languages - in which determinism is the norm. I suffer badly from the functionalitis.
Some of it is to have a committed choice when you have a number of potential examples but only want one - and the first will do. This happens to me quite a lot with I/O (for instance HTTP handlers).
The use of defaulty representations is a big problem as well, but getting rid of defaulty representations takes a bit of practice and thought. It is actually very similar to specifying a data-type with case-coverage. This fact has always made me think that greater “gradual typing” would greatly improve prolog. The task of doing this in an acceptably prology way however is a bit tricky in practice and requires really tight integration with the development environment making portability a bit tricky as well.
I’d like to support Boris’ contention that
diff/2 and in general co-routining does reduce cuts in code. The reason is that implementing relations which work in multiple modes often requires meta-logical nonsense with cuts. i.e.
p(X, Y) :- var(X), !, do_something_to_obtain_x_from_y(X,Y).
p(X, Y) :- do_something_to_obtain_y_from_x(Y,X).
I find this code deeply offensive, and yet routinely engage in such evil in order to hide the implementation details from the caller. Unfortunately it is also error prone as the reversibility of the relation must be ensured carefully by hand. Co-routining tends to yield reversibility more reliably and with far fewer cuts.
But in some cases it should be possible to obtain the same by simply reordering clauses with a “mode specialising compiler” given that the compiler was:
- aware of the acceptable modes
- allowed to reorder clauses
Both of those things seem like they would be beneficial if they could be achieved but it is no short order. The reordering of clauses is impossible to do logically unless we know that the predicate is pure - i.e. no effects including exceptions and that means being able to know such things.
I think a good mode and type system which allows the types to be a type assertion is probably the first step towards a lot of more clever ways of avoiding cut and would have other benefits as well. I just wish I had the time to put more effort into solving it.