Challenge 3: Why a Red-Cut Predicate Can't Be Reordered Freely — Possible Solution ==================================================================== // Pure Prolog facts and rules, without cut, genuinely mean the same // thing regardless of the ORDER they're written in -- this is what // "declarative" is supposed to guarantee. Reordering: // // parent(tom, bob). // parent(tom, liz). // // to: // // parent(tom, liz). // parent(tom, bob). // // changes nothing about what the predicate LOGICALLY means -- the // same set of facts is true either way, and a query like // parent(tom, X) still finds exactly the same two answers, just // possibly in a different ORDER (which itself usually doesn't matter // for correctness, only for which answer comes back "first"). // // A predicate relying on a red cut is genuinely different, using // classify/2 from Challenge 2 as the concrete example: // // classify(X, negative) :- X < 0, !. // classify(X, zero) :- X =:= 0, !. // classify(X, positive). // // Swapping the ORDER of these three clauses -- say, moving the // positive clause (classify(X, positive).) to be FIRST instead of // last -- would completely break the predicate's actual meaning. // classify(-5, R) would then match the (now-first) positive clause // immediately, with no guard to reject it, reporting the WRONG // answer (positive) for a negative number, before ever reaching the // negative clause at all. The correctness of this predicate // genuinely depends on trying the guarded clauses BEFORE the // unguarded catch-all one, in that specific order -- exactly the // "correctness tied to execution order" cost the chapter names as // the real price of a red cut. Pure fact/rule reordering is safe; // reordering clauses that rely on red cuts and fall-through logic is // not. WHY THIS WORKS AS AN ANSWER ------------------------------ This contrasts pure, reorderable facts against classify/2's own real cut-dependent clause ORDER, giving a concrete example of exactly what breaks (the wrong classification for a negative number) if the clauses were reordered, directly demonstrating the chapter's own claim that cut ties correctness to execution order.