% cut2.pl:  This is almost exactly the same database as that of cut1,
% with the addition of (you guessed it!) a cut in-between the previous
% goals.  Here's the result:
%
% ?- cartesian(A,B).
% A = a,
% B = 1 ;
% A = a,
% B = 2.
%
% As before, Prolog will first unify A with a.  The cut is immediately
% satisfied, and Prolog continues, for the moment, as if nothing has
% changed from cut1.pl.  B is unified with 1, producing "A = a, B = 1".
% Prolog backtracks, next unifying B with 2, producing "A = a, B = 2".
% Thanks to the cut, Prolog cannot unify B with another value.
% Ordinarily, as in cut1.pl, Prolog would backtrack to see
% if A can be unified with something else, but here the cut says,
% "I'm preventing backtracking on firstvalue()," which brings the search
% to a halt.  Think of "!" as a one-way glass:  We can see (proceed)
% through it looking left to right, but cannot see (backtrack) through it
% looking right to left.

firstvalue(a).
firstvalue(b).
secondvalue(1).
secondvalue(2).

cartesian(X,Y) :- firstvalue(X), !, secondvalue(Y).
