What is up with the cut (!)

This reminded of a post a while back in which I rewrote the JavaScript switch example at switch - JavaScript | MDN in Prolog like so:

fruit('Oranges') :- !,
    format("Oranges are $0.59 a pound.~n", []).

fruit(Fruit) :-
    member(Fruit, ['Mangoes', 'Papayas']), !,
    format("~w are $2.79 a pound.~n", [Fruit]).

fruit(Fruit) :-
   format("Sorry, we are out of ~w.~n", [Fruit]).

Prolog has a similar bug/feature as JavaScript’s fall-through cases in that the default case will always be matched if something equivalent to JavaScript’s break or return isn’t called by an earlier matching case.

A difference between JavaScript’s break and Prolog’s ! is it’s good style in Prolog to cut as soon possible (whereas break or return are usually at the end of case blocks in JavaScript), so Prolog’s cuts are akin to guards as described by Edsger Dijkstra in this famous paper.

As in any programming language, one often needs conditionals with some default action in Prolog, and using cuts is the easy way to achieve that.