;TUPSET.CAM #include jno.cam _fn <- "tupset.cam"; ;------- Tuple-set functionality ---------------------------------------------- ; valores: A x (A->B)-set --> B-set valores(a,r) = { t[a] | t <- r : a in dom(t) }; ; tupSUM: (A->B) --> INT tupSUM(t) = SUM(< t[a] | a <- dom(t): is-INT(t[a]) >); ; tupSetColSUM: A x (A->B)-set --> INT tupSetColSUM(a,r) = SUM(< t[a] | t <- r : a in dom(t) && is-INT(t[a]) >); tupSetColSUM(a,r) = SUM(< t[a] | t <- r : (a in dom(t) && is-INT(t[a])) >); ; atributos: (A->B)-set --> A-set atributos(r) = UNION({ dom(t) | t <- r }); contagem(a,v,r) = card({ t | t <- r : a in dom(t) && t[a]==v }); histograma(a,r) = [ v -> contagem(a,v,r) | v <- valores(a,r) ]; dumpTupSet(s) = stdDump(TupSet2StrLst(s)); FUNC colsum(t:(A->B)-set,l:A-list):INT RETURN < tupSetColSUM(a,t) | a <- l >; FUNC TupSet2StrLst(s: Tuple-set): STR-list RETURN if s=={} then < "No records found" > else let (r={ AtomFF2STRFF(t) | t <- s }, A=atributos(r), x=[ a -> 2.+MAX({strlen(v) | v <- {a} U valores(a,r)}) | a <- A ], L= < a | a <- A >, hline= < strcat("+",strfill("-",x[a])) | a <- L >^<"+\n">, rl= < hline, < strcat("|",strcenter(a,x[a])) | a <- L >^<"|\n">, hline > ^ < < strcat("|", if ~(a in dom(t)) then strcenter("",x[a]) else if is-STR(t[a]) then strleft(t[a],x[a]) else if is-INT(t[a]) then strright(itoa(t[a]),x[a]) else strcenter("!",x[a]) ) | a <- L >^<"|\n"> | t <- r > ^ < hline >) in flatten(rl); FUNC TupSet2LaTeXStrLst(r: Tuple-set): STR-list RETURN if r=={} then < "No records found" > else let (A=atributos(r), L= < a | a <- A > ;,xxx=princ("strlen=",strlen(hline),"\n") ) in if L==<> then < "No attributes in table" > else let (h=head(L), t=tail(L)) in < "\\begin{tabular}{", Strcat(< "|c" | a <- L >^<"|}">), "\\hline\n" > ^ addStrSep(< strcat("\\bf ",a) | a <- L >,"&") ^ < "\\\\\\hline\\hline\n" > ^ < Strcat( addStrSep(< if a in dom(t) then t[a] else "" | a <- L >,"&") ^<"\\\\\\hline\n">) | t <- r > ^ < "\\end{tabular}\n" >; FUNC TupSet2StrLstAlt(r: Tuple-set): STR-list RETURN if r=={} then < "No records found" > else let (A=atributos(r), x=[ a -> 2.+MAX({strlen(v) | v <- {a} U valores(a,r)}) | a <- A ], L= < a | a <- A >, hline= Strcat(< strcat("+",strfill("-",x[a])) | a <- L >^<"+\n">) ;,xxx=princ("strlen=",strlen(hline),"\n") ) in < hline, Strcat(< strcat("|",strcenter(a,x[a])) | a <- L >^<"|\n">), hline > ^ CONC(< < Strcat(< strcat("|", strcenter(if a in dom(t) then t[a] else "",x[a])) | a <- L >^<"|\n">), hline > | t <- r >);