[m-users.] Announcement (aggregates module) + questions (window functions)

Mark Clements mark.clements at ki.se
Fri Dec 30 00:27:54 AEDT 2022


As an announcement, I have drafted a Mercury module for aggregates: see https://github.com/mclements/mercury-aggregates . This includes bag and set semantics for count, min, max, sum, avg, geom_mean, var, median and quantile.

As an extension, I have tried to implement window functions (https://en.wikipedia.org/wiki/Window_function_(SQL)) in Mercury: see https://github.com/mclements/mercury-aggregates/blob/main/test_window.m for an example. First, has anyone previously worked with window functions in Mercury? Second, is the syntax that I have used sensible (see code snippet below)? Here, bag_cum_sum and bag_row_number are functions that return a predicate, which is concise, but perhaps not obvious.

%% patient and visit are nondet predicates
main(!IO) :-
    print_line("{Id, RowNumber, Date, Score, CumScore}", !IO),
    aggregate((pred({Id,RowNumber,Datei,Scorei,CumScorei}::out) is nondet :-
                   patient(Id,_),
                   Combined = (pred(Date::out,Score::out) is nondet :- visit(Id,Date,Score)),
                   Combined(Datei,Scorei),
                   bag_cum_sum(Combined)(Datei,CumScorei),
                   Dates = (pred(Date::out) is nondet :- Combined(Date,_)),
                   bag_row_number(Dates)(Datei,RowNumber)),
              print_line,
              !IO).

Third, I have sought to stay with nondet predicates, with the implementation internally using lists -- is there a better approach?

Sincerely, Mark.


När du skickar e-post till Karolinska Institutet (KI) innebär detta att KI kommer att behandla dina personuppgifter. Här finns information om hur KI behandlar personuppgifter<https://ki.se/medarbetare/integritetsskyddspolicy>.


Sending email to Karolinska Institutet (KI) will result in KI processing your personal data. You can read more about KI’s processing of personal data here<https://ki.se/en/staff/data-protection-policy>.


More information about the users mailing list