% -*-Prolog-*-
% thisis similar to the sum example.
% given a set of assertions of the form:
%
% income(person,source,year,$)
%
% this rule will maintain a set of yearly totals of the form
%
% total_income(person,year,$)
%
income(Person,Source,Year,Dollars) => {increment_income(Person,Year,Dollars)}.
=> fcUndoMethod(increment_income(P,Y,D),decrement_income(P,Y,D)).
increment_income(P,Y,D) :-
(retract(total_income(P,Y,Old)) -> New is Old+D ; New = D),
assert(total_income(P,Y,New)).
decrement_income(P,Y,D) :-
retract(total_income(P,Y,Old)),
New is Old-D,
assert(total_income(P,Y,New)).