It never (i.e. never) makes sense to have a varM in a fact variable, because that is completely equivalent to having the value directly in the fact variable, except that it becomes more complex.
Yes, I was getting carried away trying to apply these new routines.
(I find it strange that you mix values and sums in a single list.)
The sample code would produce the raw data for a single column financial report subtotalled by department. I attached an example of a simple multi-column report that displays data in vpiTableed (this screen capture is not related to the sample code in any way). Subtotals may be present for multi-company reports or any number of other reasons.
Pre if-then-else functionality I had more clauses and an output parameter. Using the same example would be something like below. When preparing data for a detailed multi-company financial report comparing Actual against Budget against Prior Years with averages and percentage columns these predicates to collect the data become quite large and complex so I try to think of other ways to simplify the data collection. The reports themselves are not static in the sense that they're pre-defined. It's strictly parameter driven from the user point-of-view and everything else is handled by the system.
Thanks for the feedback Thomas and setting me straight on proper usage. I'll let it sink in and hopefully come up with more productive methods.
David
Note: the following code does not relate to the jpg attached.
Assume separate predicates addSubtotals, getSubTotal and getTotal.
Code: Select all
class predicates
collect_data(unsigned,gmttime*,gmttime*,unsigned_list,real_list) procedure (i,i,i,i,o).
clauses
collect_data(Code,[Date|T2],DATES,[DEPT|T3],[Real|T4]):-
if dataDB(Code,Date2,DEPT,Real) and Date2:sametime(Date)
then retract(dataDB(Code,Date2,DEPT,Real))
else Real = 0
end if,
addSubtotals(Real),!,
collect_data(Code,T2,DATES,[DEPT|T3],T4). %collect next date
collect_data(Code,[],DATES,[_DEPT|T3],[SubTotal|T4]):- %end of data for DEPT (all dates collected)
getSubTotal(SubTotal),!,
collect_data(Code,DATES,DATES,T3,T4). %collect data for next department
collect_data(_,_,_,[SubTotal|Total]):-
getSubTotal(SubTotal),
getTotal(Total).