% Negation with the cut.
% Author: Steve Wolfman
% Based on common ideas in Prolog.
% Released into the public domain.

% Negation in prolog is negation-as-failure
% to prove something true.
% That means negation(Goal) should be true
% anytime we try to prove Goal but fail.
% Prolog WILL ALLOW us to "promote" Goal
% from term to atom, which is not obvious
% but is super-cool and powerful. The cut 
% will allow us to do the rest:
negation(Goal) :- Goal, % Try to prove Goal
                        % If it fails, we backtrack to line 22.
                  !,    % If it succeeds, we reach here, and 
                        % the cut succeeds but stops us from 
                        % ever getting to line 22.
                  fail. % fail is a built-in predicate that 
                        % always fails. We built such things
                        % using dynamic a month ago!
negation(Goal).  % ALWAYS succeed if we reach this point.


% A little extra about difference lists.. that probably makes no sense ;)
diff_append(DL1-DLT1, DL2-DLT2, AL-ALT) :- DLT1 = DL2, DLT2 = ALT, AL = DL1.
diff_append(DL1-DLT1, DLT1-ALT, DL1-ALT).
