I am a newbie to Prolog and having a hard time understanding the meaning of the cut operator, !, in different contexts.
For instance, what is the effect of it in this line here? Or how to read this line in plane English
rewrite(p => q, F) :- !, rewrite(~ p or q, F).
This will be one of several
rewrite/2predicates.The cut is intended to mean that this is the only rule that handles
p => qas the first argument, so do not backtrack and check the otherrewrite/2predicates below this one.Such a cut is useful for performance, and to avoid a "catch-all"/default
rewrite(P, F)predicate which might exist.Prolog's debugging features are hugely useful to show what is going on. Start with
trace, at https://www.swi-prolog.org/pldoc/man?section=debugger