Search code examples
prologiso-prolog

Behavior of cuts in negation


The following code, as expected, outputs 123 because of backtracking:

between(1,3,X), write(X), false.

This one with the cut outputs 1, also as expected:

between(1,3,X), write(X), !, false.

But this one outputs 123 surprisingly:

between(1,3,X), write(X), not(!).

not(!) evaluates to false so in one way it makes sense that it backtracks but at the same time it should have cut and therefore have no other possibilites to explore.

The same behaviour happens with \+ instead of not/1.

Why is the cut not having any side effect when negated? For example write/1 in a not has the same side effect as when it's not in one.


Solution

  • (\+)/1 it's a metacall builtin, and (citing the !/0 docs)

    Meta calling is opaque to the cut.

    The examples, specially t4, illustrate the operational semantic