Following The Craft of Prolog advice re: cut, indeed made a speed up

Hello,

I was doing some “light” reading of The Craft of Prolog yesterday (I keep rereading it, just in case I manage to understand another thing or two), and noticed the discussion about cut (page 90,91).

In particular, that a predicate should not rely on client code to make it determinate by use of a cut – if choice points should be removed, it should be done inside the predicate.

Richard says that leaving the cut to caller code is like asking client code to close a file – an apt analogy – that made me finally understand what he meant.

I followed his advice today and lo-and-behold – my code runs faster !

Also, I have many places where I “forgot” a cut, which is now taken care off – I can now remove many superfluous cuts from my code as well.

Good to know :slight_smile:

Dan

p.s. I keep thinking that there should be a Craft’s programming style checker putting out “O’Keefe” warnings wherever code is not following his style recommendations …

3 Likes